Module: Necromancy::Control::Arrow

Extended by:
Necromancy::Control
Includes:
Category
Defined in:
lib/necromancy/control/arrow.rb

Instance Method Summary collapse

Methods included from Necromancy::Control

[], call, extended, hiding, new, using

Methods included from Category

#<, #>

Instance Method Details

#&(callable) ⇒ Necromancy

Note:
self

a -> b

Returns a -> (b, b’).

Examples:

require 'necromancy'
N = Necromancy.Arrow.new
f = lambda(&N.upcase & :capitalize & :reverse) # == ->(o) { [o.upcase, o.capitalize, o.reverse] }
f.("foo") # => ["FOO", "Foo", "oof"]

Parameters:

  • callable (Object)

    a -> b’

Returns:



19
20
21
22
23
# File 'lib/necromancy/control/arrow.rb', line 19

def &(callable)
  str = make_evaluable_string(callable)
  necromancy = "(#{@necromancy}) + (#{str})"
  self.class.new(necromancy, @references.dup)
end

#*(callable) ⇒ Necromancy

Note:
self

a -> b

Returns (a, a’) -> (b, b’).

Examples:

require 'necromancy'
N = Necromancy.Arrow.new
f = lambda(&N.to_sym * N.to_f) # == ->(a, b) { [a.to_sym, b.to_f] }
f.("x", 42) # => [:x, 42.0]

Parameters:

  • callable (Object)

    a’ -> b’

Returns:



33
34
35
36
37
# File 'lib/necromancy/control/arrow.rb', line 33

def *(callable)
  str = make_evaluable_string(callable)
  necromancy = "stack << [] << args; args = stack[-1][0..-2]; stack[-2].concat((#{@necromancy})); args = [stack[-1][-1]]; stack[-2].concat((#{str})); args = stack.pop; stack.pop"
  self.class.new(necromancy, @references.dup)
end