Skip to content

Instantly share code, notes, and snippets.

@viveksoundrapandi
Created January 16, 2020 04:03
Show Gist options
  • Save viveksoundrapandi/9a00c0fd2ce14c4d82e072c1fe734aa8 to your computer and use it in GitHub Desktop.
Save viveksoundrapandi/9a00c0fd2ce14c4d82e072c1fe734aa8 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
class Proc
def my_curry
# when my_curry is called: create a new proc and return
curried = proc do |*partial_args|
# when curried proc is called: create a closure with partial arguments and then return a new proc/lambda
l = lambda do |*remaining_args|
# when the partial rendered curried lambda is called delegate the call to original lambda with closure + current arguments
actual_args = partial_args + remaining_args
call(*actual_args)
end
end
end
end
original_lambda = ->(x, y) { p x, y }
p original_lambda
curried_proc = original_lambda.my_curry
p curried_proc
partial_renderd_lambda = curried_proc[1]
p partial_renderd_lambda
partial_renderd_lambda[2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment