module Funkify

Constants

VERSION

Public Class Methods

auto_curry_all_methods(receiver) click to toggle source
# File lib/funkify.rb, line 57
def self.auto_curry_all_methods(receiver)
  in_use = nil
  receiver.define_singleton_method(:method_added) do |name|
    return if in_use
    in_use = true
    receiver.auto_curry name
    in_use = false
  end
end
auto_curry_some_methods(names, receiver) click to toggle source
# File lib/funkify.rb, line 67
def self.auto_curry_some_methods(names, receiver)
  names.each do |name|
    m = receiver.instance_method(name)
    curried_method = nil

    receiver.class_eval do
      define_method(name) do |*args|
        curried_method ||= m.bind(self).to_proc.curry
        curried_method[*args]
      end
    end
  end
end
included(klass) click to toggle source
# File lib/funkify.rb, line 4
def self.included(klass)
  klass.extend ClassMethods
end

Public Instance Methods

_procify(obj) click to toggle source
# File lib/funkify.rb, line 48
def _procify(obj)
  case obj
  when Symbol
    method(obj).to_proc
  else
    obj.to_proc
  end
end
compose(*args) click to toggle source
# File lib/funkify.rb, line 38
def compose(*args)
  head, *tail = args
  head = _procify(head)
  if args.size <= 2
    ->(*xs) { head.(_procify(tail[0]).(*xs)) }
  else
    ->(*xs) { head.(compose(*tail)) }
  end
end
curry(obj, *args) click to toggle source
# File lib/funkify.rb, line 24
def curry(obj, *args)
  case obj
  when Symbol
    method(obj).to_proc.curry[*args]
  else
    obj.curry(*args)
  end
end
pass(*xs) click to toggle source
# File lib/funkify.rb, line 33
def pass(*xs)
  -> { xs }
end