Skip to content

Instantly share code, notes, and snippets.

@somenugget
Last active January 18, 2019 15:30
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 somenugget/9a9ec49391a45f0305ace464842096d3 to your computer and use it in GitHub Desktop.
Save somenugget/9a9ec49391a45f0305ace464842096d3 to your computer and use it in GitHub Desktop.
Currying in Ruby
# https://www.morozov.is/2019/01/11/partial-application-in-ruby.html
fun = ->(tag, text) { "<#{tag}>#{text}</#{tag}>" }
curried_fun = fun.curry
bold_fun = curried_fun.('b')
p fun.('b', 'yo') # "<b>yo</b>"
p curried_fun.('b').('yo') # "<b>yo</b>"
p bold_fun.('yo') # "<b>yo</b>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment