Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module StringApply
- def apply(*funcs)
- funcs.inject(self) { |product, func| func.call(product) }
- end
- end
- module ArrayApply
- def apply(*funcs)
- # funcs.inject(self) { |product, func| func.call(product) }
- map { |item| funcs.inject(item) { |product, func| func.call(product) } }
- end
- end
- String.include StringApply
- Array.include ArrayApply
- module ProcRefinement
- refine Proc do
- def [](*args)
- curry.(*args)
- end
- end
- end
- module ApplyRefinement
- refine Object do
- def apply(*funcs)
- funcs.inject(self) { |product, func| func.call(product) }
- end
- end
- end
- s = 'ahoj'
- func = -> (a) { puts a; a }
- s.apply(func,
- func,
- func)
Add Comment
Please, Sign In to add comment