Skip to content

Commit

Permalink
Implement Enumerable#partition and remove spec filters
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Dec 14, 2013
1 parent aeee689 commit 53fe56b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -87,7 +87,7 @@
self. Add `Struct.[]` as synonym for `Struct.new`.

* Implemented some `Enumerable` methods: `#collect_concat`, `#flat_map`,
`#reject` and `#reverse_each`.
`#reject`, `#reverse_each` and `#partition`.

## 0.5.5 2013-11-25

Expand Down
27 changes: 26 additions & 1 deletion opal/corelib/enumerable.rb
Expand Up @@ -940,7 +940,32 @@ def one?(&block)
end

def partition(&block)
raise NotImplementedError
return enum_for :partition unless block_given?

%x{
var truthy = [], falsy = [];
self.$each._p = function() {
var param = #{Opal.destructure(`arguments`)},
value = $opal.$yield1(block, param);
if (value === $breaker) {
result = $breaker.$v;
return $breaker;
}
if (#{Opal.truthy?(`value`)}) {
truthy.push(param);
}
else {
falsy.push(param);
}
};
self.$each();
return [truthy, falsy];
}
end

alias reduce inject
Expand Down
4 changes: 0 additions & 4 deletions spec/opal/filters/bugs/enumerable.rb
Expand Up @@ -48,10 +48,6 @@
fails "Enumerable#minmax returns [nil, nil] for an empty Enumerable"
fails "Enumerable#minmax min should return the minimum element"

fails "Enumerable#partition gathers whole arrays as elements when each yields multiple"
fails "Enumerable#partition returns an Enumerator if called without a block"
fails "Enumerable#partition returns two arrays, the first containing elements for which the block is true, the second containing the rest"

fails "Enumerable#reverse_each gathers whole arrays as elements when each yields multiple"

fails "Enumerable#sort gathers whole arrays as elements when each yields multiple"
Expand Down

0 comments on commit 53fe56b

Please sign in to comment.