Module: Enumerable
- Defined in:
- lib/lazing/filters.rb,
lib/lazing/transformers.rb
Instance Method Summary collapse
-
#mapping(&blk) ⇒ Object
(also: #collecting)
Lazy version of Enumerable#map.
-
#rejecting(&blk) ⇒ Object
Lazy version of Enumerable#reject.
-
#selecting(&blk) ⇒ Object
(also: #finding_all)
Lazy version of Enumerable#select.
Instance Method Details
#mapping(&blk) ⇒ Object Also known as: collecting
Lazy version of Enumerable#map
Returns the lazy collection formed by applying the given block to each member of the collection.
6 7 8 9 10 11 12 |
# File 'lib/lazing/transformers.rb', line 6 def mapping(&blk) Enumerator.new do |yielder| each do |item| yielder.yield blk.call(item) end end end |
#rejecting(&blk) ⇒ Object
Lazy version of Enumerable#reject.
Returns a lazy collection containing all elements of the collection for which the provided block returns false.
6 7 8 9 10 11 12 |
# File 'lib/lazing/filters.rb', line 6 def rejecting(&blk) Enumerator.new do |yielder| each do |item| yielder.yield item unless blk.call(item) end end end |
#selecting(&blk) ⇒ Object Also known as: finding_all
Lazy version of Enumerable#select
Returns a lazy collection containing all elements of the collection for which the provided block returns true.
18 19 20 21 22 23 24 |
# File 'lib/lazing/filters.rb', line 18 def selecting(&blk) Enumerator.new do |yielder| each do |item| yielder.yield item if blk.call(item) end end end |