Module: Option::Enumerable
Instance Method Summary collapse
- #detect ⇒ Object (also: #find)
- #flat_map(&block) ⇒ Object
- #flatten ⇒ Object
- #grep(value) ⇒ Object
- #juxt(*methods) ⇒ Object
- #map ⇒ Object (also: #collect, #collect_concat)
- #map_through(*methods) ⇒ Object
- #reduce(*args, &block) ⇒ Object (also: #inject)
- #reject(*args, &block) ⇒ Object
- #select ⇒ Object (also: #find_all)
- #to_ary ⇒ Object
Instance Method Details
#detect ⇒ Object Also known as: find
31 32 33 |
# File 'lib/optional/option/enumerable.rb', line 31 def detect from_value super end |
#flat_map(&block) ⇒ Object
27 28 29 |
# File 'lib/optional/option/enumerable.rb', line 27 def flat_map(&block) map(&block).flatten end |
#flatten ⇒ Object
9 10 11 |
# File 'lib/optional/option/enumerable.rb', line 9 def flatten from_array to_ary.flatten end |
#grep(value) ⇒ Object
41 42 43 |
# File 'lib/optional/option/enumerable.rb', line 41 def grep(value) from_array super end |
#juxt(*methods) ⇒ Object
13 14 15 |
# File 'lib/optional/option/enumerable.rb', line 13 def juxt(*methods) map { |v| methods.map { |m| v.send(m) } } end |
#map ⇒ Object Also known as: collect, collect_concat
21 22 23 |
# File 'lib/optional/option/enumerable.rb', line 21 def map from_array super end |
#map_through(*methods) ⇒ Object
17 18 19 |
# File 'lib/optional/option/enumerable.rb', line 17 def map_through(*methods) map &methods.reduce(->(x){x}){ |acc, m| ->(x) { acc.call(x).send(m) } } end |
#reduce(*args, &block) ⇒ Object Also known as: inject
49 50 51 52 53 54 |
# File 'lib/optional/option/enumerable.rb', line 49 def reduce(*args, &block) if none? && (args.size < 1 || args.size < 2 && block.nil?) raise ValueOfNoneError end super end |
#reject(*args, &block) ⇒ Object
45 46 47 |
# File 'lib/optional/option/enumerable.rb', line 45 def reject(*args, &block) from_array to_a.reject(*args, &block) end |
#select ⇒ Object Also known as: find_all
36 37 38 |
# File 'lib/optional/option/enumerable.rb', line 36 def select from_array super end |
#to_ary ⇒ Object
5 6 7 |
# File 'lib/optional/option/enumerable.rb', line 5 def to_ary to_a end |