RosettaCodeData/Task/Set-consolidation/Factor/set-consolidation.factor
2020-02-17 23:21:07 -08:00

10 lines
265 B
Factor

USING: arrays kernel sequences sets ;
: comb ( x x -- x )
over empty? [ nip 1array ] [
dup pick first intersects?
[ [ unclip ] dip union comb ]
[ [ 1 cut ] dip comb append ] if
] if ;
: consolidate ( x -- x ) { } [ comb ] reduce ;