Skip to content

Commit 59a7908

Browse files
committed
[GR-16331] Implement {Enumerable,Enumerator::Lazy}#filter.
PullRequest: truffleruby/882
2 parents f7e6d44 + dd7f828 commit 59a7908

File tree

10 files changed

+31
-20
lines changed

10 files changed

+31
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Compatibility:
88
* Exceptions from `coerce` are no longer rescued, like MRI.
99
* Implemented `Integer#{allbits?,anybits?,nobits?}`.
1010
* `Integer#{ceil,floor,truncate}` now accept a precision and `Integer#round` accepts a rounding mode.
11+
* Added missing `Enumerable#filter` and `Enumerator::Lazy#filter` aliases to the respective `select` method (#1610).
1112

1213
# 20.0.0 beta 1
1314

spec/tags/core/enumerable/filter_tags.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

spec/tags/core/enumerator/lazy/filter_tags.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

spec/tags/truffle/methods_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ fails:Public methods on Complex should include to_c
66
fails:Public methods on Complex should not include divide
77
fails:Public methods on Complex should not include marshal_load
88
fails:Public methods on Enumerable should include chain
9-
fails:Public methods on Enumerable should include filter
109
fails:Public methods on Enumerator should include +
1110
fails:Public methods on File should include birthtime
1211
fails:Public methods on File should not include inspect
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
chunk
2+
chunk_while
3+
collect
4+
collect_concat
5+
drop
6+
drop_while
7+
enum_for
8+
filter
9+
find_all
10+
flat_map
11+
force
12+
grep
13+
grep_v
14+
lazy
15+
map
16+
reject
17+
select
18+
slice_after
19+
slice_before
20+
slice_when
21+
take
22+
take_while
23+
to_enum
24+
uniq
25+
zip

spec/truffle/methods_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. This
1+
# Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved. This
22
# code is released under a tri EPL/GPL/LGPL license. You can use it,
33
# redistribute it and/or modify it under the terms of the:
44
#
@@ -19,7 +19,7 @@
1919
modules = [
2020
BasicObject, Kernel, Object,
2121
Module, Class,
22-
Enumerable, Enumerator, Range,
22+
Enumerable, Enumerator, Enumerator::Lazy, Range,
2323
Numeric, Integer, Float,
2424
Rational, Complex,
2525
Array, Hash, String,

src/main/java/org/truffleruby/core/array/ArrayNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ private void reverse(ArrayOperationNodes.ArrayGetNode getNode, ArrayOperationNod
19281928

19291929
}
19301930

1931-
@CoreMethod(names = "select", needsBlock = true, enumeratorSize = "size")
1931+
@CoreMethod(names = { "select", "filter" }, needsBlock = true, enumeratorSize = "size")
19321932
@ImportStatic(ArrayGuards.class)
19331933
@ReportPolymorphism
19341934
public abstract static class SelectNode extends YieldingCoreMethodNode {

src/main/ruby/truffleruby/core/array.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,6 @@ def fetch(idx, default=undefined)
501501
self
502502
end
503503

504-
alias_method :filter, :select
505-
506504
def first(n = undefined)
507505
return at(0) if undefined.equal?(n)
508506

src/main/ruby/truffleruby/core/enumerable.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ def find_all
642642
end
643643

644644
alias_method :select, :find_all
645+
alias_method :filter, :find_all
645646

646647
def find_index(value=undefined)
647648
if undefined.equal? value

src/main/ruby/truffleruby/core/enumerator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ def select
379379
end
380380
end
381381
alias_method :find_all, :select
382+
alias_method :filter, :select
382383

383384
def reject
384385
raise ArgumentError, 'Lazy#reject requires a block' unless block_given?

0 commit comments

Comments
 (0)