module RightCurry

Public Instance Methods

reduce_curry(arguments, memo, index) click to toggle source
# File lib/right_curry.rb, line 15
def reduce_curry(arguments, memo, index)
  ->(next_argument) { arguments.merge!(index => next_argument) && memo }
end
right_curry() click to toggle source
# File lib/right_curry.rb, line 5
def right_curry
  return call if arity.zero?

  Hash.new.then do |arguments|
    ->(first) { call(first, *arguments.values.reverse) }
      .then { |rightmost| [rightmost, *(1...arity)] }
      .reduce(&method(:reduce_curry).curry[arguments])
  end
end