Class: Symbol

Inherits:
Object show all
Defined in:
lib/coroutines/operators.rb

Instance Method Summary collapse

Instance Method Details

#<=(source) ⇒ Object

:call-seq:

sym <= trans  -> new_trans
sym <= enum   -> new_enum

Equivalent to sym.to_trans <= trans/enum, except that it uses a more efficient implementation.



85
86
87
# File 'lib/coroutines/operators.rb', line 85

def <=(source)
  to_proc <= source
end

#>=(sink) ⇒ Object

:call-seq:

sym >= trans  -> new_trans
sym >= sink   -> new_consumer

Equivalent to sym.to_trans >= trans/sink, except that it uses a more efficient implementation.



95
96
97
# File 'lib/coroutines/operators.rb', line 95

def >=(sink)
  to_proc >= sink
end

#to_transObject

:call-seq:

sym.to_trans -> transformer

Allows implicit conversion of Symbol to Transformer. The transformer accepts any objects as input, calls the method given by sym on each and outputs all non-nil results of the method. See Proc#to_trans for details.

example:

collector = [] <= :to_s
collector << 1 << 4 << 9
collector.close # => ["1", "4", "9"]


70
71
72
73
74
75
76
77
# File 'lib/coroutines/operators.rb', line 70

def to_trans
  Transformer.new do |y|
    loop do
      value = y.await.send self
      y.yield value unless value.nil?
    end
  end
end