Module: Necromancy::Control::Applicative

Extended by:
Necromancy::Control
Included in:
Alternative
Defined in:
lib/necromancy/control/applicative.rb

Instance Method Summary collapse

Methods included from Necromancy::Control

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

Instance Method Details

#*(callable) ⇒ Necromancy Also known as: __Applicative_Astarisk

Note:
self

a -> b -> c

Returns a -> c.

Examples:

require 'necromancy'
N = Necromancy.Applicative.new
f = lambda(&N.+ * N) # == ->(o) {o + o}
f.(42) # => 84

Parameters:

  • callable (Object)

    a -> b

Returns:



16
17
18
19
# File 'lib/necromancy/control/applicative.rb', line 16

def *(callable)
  str = make_evaluable_string(callable)
  self.class.new("args.concat((#{str})); #{@necromancy}", @references.dup)
end

#**(callable) ⇒ Necromancy

Note:
self

a -> b

A variant of #* with the arguments reversed.

Examples:

require 'necromancy'
N = Necromancy.Applicative.new
f = lambda(&N ** :+) # == ->(o) {o + o}
f.(42) # => 84

Parameters:

  • callable (Object)

    a -> b -> c

Returns:



30
31
32
33
# File 'lib/necromancy/control/applicative.rb', line 30

def **(callable)
  str = make_evaluable_string(callable)
  self.class.new(str, @references.dup).__Applicative_Astarisk(self)
end

#<<(callable) ⇒ Necromancy

Note:
self

a -> b

Sequence actions, discarding the value of the callable.

Examples:

require 'necromancy'
N = Necromancy.Applicative.new
f = lambda(&N.succ << N.pred) # == ->(o) {o.pred; o.succ}
f.(42) # => 43

Parameters:

  • callable (Object)

    a -> _

Returns:



44
45
46
# File 'lib/necromancy/control/applicative.rb', line 44

def <<(callable)
  self.class.new("args.pop; #{@necromancy}", @references.dup).__Applicative_Astarisk(callable)
end

#>>(callable) ⇒ Necromancy

Note:
self

a -> _

Sequence actions, discarding the value of self.

Examples:

require 'necromancy'
N = Necromancy.Applicative.new
f = lambda(&N.succ >> N.pred) # == ->(o) {o.succ; o.pred}
f.(42) # => 41

Parameters:

  • callable (Object)

    a -> b

Returns:



57
58
59
60
# File 'lib/necromancy/control/applicative.rb', line 57

def >>(callable)
  str = make_evaluable_string(callable)
  self.class.new("args.pop; #{str}", @references.dup).__Applicative_Astarisk(self)
end