Last active
October 23, 2020 01:38
-
-
Save dkinzer/b71e72e6f207bb4c101fa174dd77c01e to your computer and use it in GitHub Desktop.
compose in Ruby defined as a reduction of its arguments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compose(*args) | |
identity = ->(x) { x } | |
args.reduce(identity) do |a, b| | |
if b.is_a? Proc | |
a >> b | |
else | |
a >> method(b) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment