Last active
January 18, 2019 15:30
-
-
Save somenugget/9a9ec49391a45f0305ace464842096d3 to your computer and use it in GitHub Desktop.
Currying in Ruby
This file contains 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
# 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