Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Stealing some vague ideas from Applicatives in Haskell, probably wrongly but it amuses me so...
class Symbol
def ap(*applied_args)
-> *block_args {
if applied_args.empty?
receiver, *new_args = block_args[0]
receiver.send(self, *new_args)
else
self.to_proc.call(*block_args, *applied_args)
end
}
end
end
(1..3).map(&:+.ap(5))
=> [6, 7, 8]
[1,2,3].zip([2, 3, 4]).map(&:+.ap)
=> [3, 5, 7]
{ 'a' => 'b', 'b' => 'a' }.map(&:join.ap(' : '))
=> ["a : b", "b : a"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.