How to combine two procs into one?
More sugar, not really recommended in production code
class Proc
def *(other)
->(*args) { self[*other[*args]] }
end
end
a = ->(x){x+1}
b = ->(x){x*10}
c = b*a
c.call(1) #=> 20
a = Proc.new { |x| x + 1 }
b = Proc.new { |x| x * 10 }
c = Proc.new { |x| b.call(a.call(x)) }
you could create a union operation like so
class Proc
def union p
proc {p.call(self.call)}
end
end
def bind v
proc { v}
end
then you can use it like this
a = -> (x) { x + 1 }
b = -> (x) { x * 10 }
c = -> (x) {bind(x).union(a).union(b).call}