Created
January 16, 2020 04:03
-
-
Save viveksoundrapandi/9a00c0fd2ce14c4d82e072c1fe734aa8 to your computer and use it in GitHub Desktop.
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
# 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