Method: Kernel#fn
- Defined in:
- lib/shenanigans/kernel/fn.rb
#fn(*funs) ⇒ Object
Composes a list of functions. Functions can be specified as symbols or lambdas.
["foo bar", "baz qux"].map &fn(:split, :last)
#=> ["bar", "qux"]
(1..3).map &fn(:next, -> x { x * x }, -> x { x.to_f / 2 } )
#=> [2.0, 4.5, 8.0]
9 10 11 12 13 14 15 |
# File 'lib/shenanigans/kernel/fn.rb', line 9 def fn(*funs) -> x do funs.inject(x) do |v,f| Proc === f ? f.call(v) : v.send(f) end end end |