Skip to content

Instantly share code, notes, and snippets.

@oem
Created February 18, 2011 21:00
Show Gist options
  • Save oem/834395 to your computer and use it in GitHub Desktop.
Save oem/834395 to your computer and use it in GitHub Desktop.
kestrels in rails
# 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