Skip to content

Commit

Permalink
Implement Enumerable#reject 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 f9d578e commit 7dae682
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -86,7 +86,8 @@
* Fix various `Struct` methods. Fixed `#each` and `#each_pair` to return
self. Add `Struct.[]` as synonym for `Struct.new`.

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

## 0.5.5 2013-11-25

Expand Down
25 changes: 25 additions & 0 deletions opal/corelib/enumerable.rb
Expand Up @@ -945,6 +945,31 @@ def partition(&block)

alias reduce inject

def reject(&block)
return enum_for :reject unless block_given?

%x{
var result = [];
self.$each._p = function() {
var param = #{Opal.destructure(`arguments`)},
value = $opal.$yield1(block, param);
if (value === $breaker) {
result = $breaker.$v;
return $breaker;
}
if (#{Opal.falsy?(`value`)}) {
result.push(param);
}
};
self.$each();
return result;
}
end
def reverse_each(&block)
raise NotImplementedError
end
Expand Down
4 changes: 0 additions & 4 deletions spec/opal/filters/bugs/enumerable.rb
Expand Up @@ -52,10 +52,6 @@
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#reject gathers whole arrays as elements when each yields multiple"
fails "Enumerable#reject returns an Enumerator if called without a block"
fails "Enumerable#reject returns an array of the elements for which block is false"

fails "Enumerable#reverse_each gathers whole arrays as elements when each yields multiple"
fails "Enumerable#reverse_each returns an Enumerator if no block given"
fails "Enumerable#reverse_each traverses enum in reverse order and pass each element to block"
Expand Down

0 comments on commit 7dae682

Please sign in to comment.