call | -> | update |
Use a Proc as an observable.
CREDIT: Tim Pease |
Wrap the argument in a proc. Simply returns the argument if it is already a Proc object.
TODO: Would this make more sense as `Kernel#Proc()` method,
akin to `Integer()` and the like?
Returns [Proc]
Credit: Sean Mackesey
Operator for Proc#compose and Integer#times_collect/of.
a = lambda { |x| x + 4 } b = lambda { |y| y / 2 } (a * b).call(4) #=> 6 (b * a).call(4) #=> 4
CREDIT: Dave
Returns a new proc that is the functional composition of two procs, in order.
a = lambda { |x| x + 4 } b = lambda { |y| y / 2 } a.compose(b).call(4) #=> 6 b.compose(a).call(4) #=> 4
CREDIT: Dave
Convert Proc to method.
object = Object.new function = lambda { |x| x + 1 } function.to_method(object, 'foo') object.foo(1) #=> 2