Union¶
public defstruct Union <: Shape :
shapes: Tuple<Shape>
with:
constructor => #Union
public defn Union (ss:Seqable<Shape|Seqable>) :
val ss* = generate<Shape> :
let loop (s:Shape|Seqable = ss) :
match(s) :
(s:Union) : do(yield, shapes(s))
(s:Shape) : yield(s)
(s:Seqable) : do(loop, s)
if empty?(ss*) :
fatal("Cannot form union from no shapes.")
else :
val s0 = next(ss*)
if empty?(ss*) : s0
else : #Union(to-tuple(cat([s0], ss*)))
Union([Circle(1.0), Rectangle(4.0, 0.5)])