Skip to content

Instantly share code, notes, and snippets.

@dkinzer
Last active October 23, 2020 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkinzer/b71e72e6f207bb4c101fa174dd77c01e to your computer and use it in GitHub Desktop.
Save dkinzer/b71e72e6f207bb4c101fa174dd77c01e to your computer and use it in GitHub Desktop.
compose in Ruby defined as a reduction of its arguments.
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