lib/abstractivator/proc_ext.rb in abstractivator-0.0.24 vs lib/abstractivator/proc_ext.rb in abstractivator-0.0.25

- old
+ new

@@ -23,9 +23,23 @@ # proc { |x| f.call(g.call(h.call(x))) } def self.compose(*procs) procs.map(&:to_proc).inject_right(identity) { |inner, p| p.compose(inner) } end + # composes procedures in reverse order. + # useful for applying a series of transformations. + # pipe(f, g, h) returns the procedure + # proc { |x| h.call(g.call(f.call(x))) } + def self.pipe(*procs) + Proc.compose(*procs.reverse) + end + + # makes a pipeline transform as with Proc::pipe + # and applies it to the given value. + def self.pipe_value(value, *procs) + Proc.pipe(*procs).call(value) + end + # returns the identity function def self.identity proc {|x| x} end