Module: Funkify

Defined in:
lib/funkify.rb,
lib/funkify/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

._procify(obj) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/funkify.rb', line 35

def _procify(obj)
  case obj
  when Symbol
    method(obj).to_proc
  else
    obj.to_proc
  end
end

.compose(*args) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/funkify.rb', line 25

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) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/funkify.rb', line 16

def curry(obj, *args)
  case obj
  when Symbol
    method(obj).to_proc.curry[*args]
  else
    obj.curry(*args)
  end
end

.included(klass) ⇒ Object



4
5
6
# File 'lib/funkify.rb', line 4

def self.included(klass)
  klass.extend ClassMethods
end