Module: Aqueductron::Buildering

Included in:
Duct
Defined in:
lib/aqueductron/buildering.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.expand_function(expansion) ⇒ Object



62
63
64
65
66
67
# File 'lib/aqueductron/buildering.rb', line 62

def expand_function(expansion)
  ->(piece, msg) do
    next_piece = Inlet.new(piece.destination, :not_done).flow(expansion.call(msg))
    Piece.new(next_piece, expand_function(expansion))
  end
end

.filter_function(predicate) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/aqueductron/buildering.rb', line 75

def filter_function(predicate)
  ->(piece, msg) do
    if(predicate.call(msg)) then
      piece.pass_on(msg, filter_function(predicate))
    else
      piece #don't change
    end
  end
end

.map_function(transform) ⇒ Object



69
70
71
72
73
# File 'lib/aqueductron/buildering.rb', line 69

def map_function(transform)
  ->(piece, msg) do
    piece.pass_on(transform.call(msg), map_function(transform))
  end
end

.take_function(how_many) ⇒ Object

this will either return a Result or a Piece



52
53
54
55
56
57
58
59
60
# File 'lib/aqueductron/buildering.rb', line 52

def take_function(how_many) # this will either return a Result or a Piece
  what_to_do = ->(piece, msg) do
    if (how_many == 0) then # this is a little inefficient. One extra piece of info will be read
      piece.send_eof
    else
      piece.pass_on(msg, take_function(how_many -1))
    end
  end
end

Instance Method Details

#answer(monoid) ⇒ Object



11
12
13
# File 'lib/aqueductron/buildering.rb', line 11

def answer(monoid)
  answer_int(EndPiece.new(monoid))
end

#countObject



15
16
17
# File 'lib/aqueductron/buildering.rb', line 15

def count
  answer_int(CountingEndPiece.new)
end

#custom(piece) ⇒ Object



31
32
33
# File 'lib/aqueductron/buildering.rb', line 31

def custom(piece)
   attach(piece)
end

#expand(transform) ⇒ Object



35
36
37
# File 'lib/aqueductron/buildering.rb', line 35

def expand(transform)
  attach(expand_function(transform))
end

#keeping(predicate) ⇒ Object



23
24
25
# File 'lib/aqueductron/buildering.rb', line 23

def keeping(predicate)
  attach(filter_function(predicate))
end

#lastObject



47
48
49
# File 'lib/aqueductron/buildering.rb', line 47

def last
  answer_int(LastEndPiece.new)
end

#partition(categorize, make_new_path) ⇒ Object



43
44
45
# File 'lib/aqueductron/buildering.rb', line 43

def partition(categorize, make_new_path)
  answer_int(SpontaneousJointPiece.new({}, categorize, make_new_path))
end

#split(paths) ⇒ Object



39
40
41
# File 'lib/aqueductron/buildering.rb', line 39

def split(paths)
  answer_int(JointPiece.new(paths))
end

#take(how_many) ⇒ Object



19
20
21
# File 'lib/aqueductron/buildering.rb', line 19

def take(how_many)
  attach(take_function(how_many))
end

#through(transform) ⇒ Object



27
28
29
# File 'lib/aqueductron/buildering.rb', line 27

def through(transform)
  attach(map_function(transform))
end