Class: Egison::Set

Inherits:
Object show all
Defined in:
lib/egison/matcher.rb

Class Method Summary collapse

Class Method Details

.uncons(val) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/egison/matcher.rb', line 69

def uncons(val)
  match_all(val) do
    with(List.(*_, _x, *_)) do
      [x, val]
    end
  end
end

.uncons_stream(val, &block) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/egison/matcher.rb', line 77

def uncons_stream(val, &block)
  if !(val.kind_of?(Array) || val.kind_of?(Egison::LazyArray))
    val = test_conv_lazy_array(val)
  end
  stream = match_stream(val) {
    with(List.(*_, _x, *_)) do
      [x, val]
    end
  }
  stream.each(&block)
end

.unjoin(val) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/egison/matcher.rb', line 89

def unjoin(val)
  val2 = val.clone
  xs = []
  ys = val2.clone
  rets = [[xs, ys]]
  if val2.empty?
    rets
  else
    x = val2.shift
    ys2 = val2.clone
    rets2 = unjoin(ys2)
    rets = (rets2.map { |xs2, _| [xs2, ys] }) + (rets2.map { |xs2, ys2| [[x] + xs2, ys] })
    rets
  end
end

.unjoin_stream(val, &block) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/egison/matcher.rb', line 105

def unjoin_stream(val, &block)
  if !(val.kind_of?(Array) || val.kind_of?(Egison::LazyArray))
    val = test_conv_lazy_array(val)
  end
  val2 = val.clone
  xs = []
  ys = val2.clone
  block.([xs, ys])
  unless val2.empty?
    x = val2.shift
    ys2 = val2.clone
    unjoin_stream(ys2) do |xs2, _|
      block.([xs2, ys]) unless xs2.empty?
      block.([[x] + xs2, ys])
    end
  end
end