Set consolidation: Difference between revisions

Content added Content deleted
(→‎{{header|Perl 6}}: use more compact conditional)
(→‎{{header|Perl 6}}: use empty list for degenerate case rather than single item, use pronouns instead of x and y)
Line 239: Line 239:
=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{works with|niecza|2012-06}}
{{works with|niecza|2012-06}}
<lang perl6>multi consolidate(Set $x) { $x }
<lang perl6>multi consolidate() { () }
multi consolidate(Set $x is copy, *@y) {
multi consolidate(Set \this is copy, *@those) {
gather {
gather {
for consolidate |@y -> $y {
for consolidate |@those -> \that {
if +($x$y) { $x ∪= $y }
if +(thisthat) { this ∪= that }
else { take $y }
else { take that }
}
}
take $x;
take this;
}
}
}
}