Class: Arrows::Proc

Inherits:
Proc
  • Object
show all
Defined in:
lib/arrows/proc.rb

Instance Method Summary collapse

Instance Method Details

#%(f) ⇒ Object

concurrent composition



18
19
20
# File 'lib/arrows/proc.rb', line 18

def %(f)
  Arrows.concurrent self, Arrows.lift(f)
end

#/(f) ⇒ Object

fanout composition



13
14
15
# File 'lib/arrows/proc.rb', line 13

def /(f)
  Arrows.fanout self, Arrows.lift(f)
end

#<=>(g) ⇒ Object

feedback (aka ArrowLoop) composition



28
29
30
# File 'lib/arrows/proc.rb', line 28

def <=>(g) 
  Arrows.feedback self, g
end

#>=(f) ⇒ Object

applicative fmap



3
4
5
# File 'lib/arrows/proc.rb', line 3

def >=(f)
  Arrows.fmap self, Arrows.lift(f)
end

#>>(f) ⇒ Object

standard composition



8
9
10
# File 'lib/arrows/proc.rb', line 8

def >>(f)
  Arrows.compose self, Arrows.lift(f)
end

#^(f) ⇒ Object

fork composition



23
24
25
# File 'lib/arrows/proc.rb', line 23

def ^(f)
  Arrows.fork self, f
end

#memoizeObject

Returns a memoizing version of this proc



33
34
35
36
# File 'lib/arrows/proc.rb', line 33

def memoize
  cache = {}
  Arrows.lift -> (args) { cache.has_key?(args) ? cache[args] : (cache[args] = self[args]) }
end

#rescue_from(error_klass = StandardError) ⇒ Object

rescues errors from procs



39
40
41
42
43
44
45
46
47
# File 'lib/arrows/proc.rb', line 39

def rescue_from(error_klass=StandardError)
  Arrows.lift -> (args) {
    begin
      self[args]
    rescue error_klass => e
      yield e, args
    end
  }
end