Created
February 18, 2011 21:00
-
-
Save oem/834395 to your computer and use it in GitHub Desktop.
kestrels in rails
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
# in Combinatory Logic, a Kestrel is a function that returns a constant function | |
# An example would be to have a return value and injecting some side effects before returning the value | |
def first_user_notified | |
user = User.first | |
user.send_email("foo") | |
user | |
end | |
# => first user | |
# and now with a kestrel using "returning" - this is an example in rails | |
def first_user_notified | |
returning User.first do |user| | |
user.send_email | |
end | |
end | |
# => first user | |
# ruby gives you tap on all objects, which is similar to the rails-specific "returning" | |
User.first.tap do |user| | |
user.send_email | |
end | |
# => first user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment