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

#>=(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



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

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

#rescue_from(error_klass = StandardError, &block) ⇒ Object

rescues errors from procs



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

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