Class: Multiset

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

Class Method Summary collapse

Class Method Details

.uncons(val) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/egison/matcher.rb', line 48

def uncons(val)
  accept_array_only(val)
  rets = val.map {|x|
    val2 = val.clone
    val2.delete_at(val2.find_index(x))
    [x, val2]
  }
  rets
end

.unjoin(val) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/egison/matcher.rb', line 58

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