module Enumerable
Public Instance Methods
enum >= sink → obj
click to toggle source
enum >= trans → new_enum
In the first form, iterate over enum
and write each result to
sink
using <<; then return the result of sink.close.
In the second form, create a new Enumerator
by connecting the output of enum
to the input of
trans
(which must be convertible to a Transformer using the to_trans method).
# File lib/coroutines/operators.rb, line 14 def >=(other) if other.respond_to? :<< begin each { |x| other << x } rescue StopIteration end other.close elsif other.respond_to? :to_trans other <= self end end
filter_map {|obj| block } → array
click to toggle source
For each obj
in in enum
, calls
block
, and collects its non-nil return values into a new
array
.
# File lib/coroutines.rb, line 38 def filter_map(&block) map(&block).compact end
out_connect(sink) → obj
click to toggle source
out_connect(trans) → new_enum
In the first form, iterate over enum
and write each result to
sink
using <<; then return the result of sink.close.
In the second form, create a new Enumerator
by connecting the output of enum
to the input of
trans
(which must be convertible to a Transformer using the to_trans method).
# File lib/coroutines.rb, line 19 def out_connect(other) if other.respond_to? :<< begin each { |x| other << x } rescue StopIteration end other.close elsif other.respond_to? :to_trans other.to_trans.in_connect(self) end end