set_union.pm6 (rakudo-2020.09) | : | set_union.pm6 (rakudo-2020.10) | ||
---|---|---|---|---|
# This file implements the following set operators: | # This file implements the following set operators: | |||
# (|) union (ASCII) | # (|) union (ASCII) | |||
# ∪ union | # ∪ union | |||
proto sub infix:<(|)>(|) is pure {*} | proto sub infix:<(|)>(|) is pure {*} | |||
multi sub infix:<(|)>() { set() } | multi sub infix:<(|)>() { set() } | |||
multi sub infix:<(|)>(QuantHash:D \a) { a } # Set/Bag/Mix | multi sub infix:<(|)>(QuantHash:D \a) { a } # Set/Bag/Mix | |||
multi sub infix:<(|)>(Any \a) { a.Set } # also for Iterable/Map | ||||
multi sub infix:<(|)>(Setty:D \a, Setty:D \b) { | multi sub infix:<(|)>(Setty:D \a, Setty:D \b) { | |||
nqp::if( | nqp::if( | |||
(my \araw := a.RAW-HASH) && nqp::elems(araw), | (my \araw := a.RAW-HASH) && nqp::elems(araw), | |||
nqp::if( # first has elems | nqp::if( # first has elems | |||
(my \braw := b.RAW-HASH) && nqp::elems(braw), | (my \braw := b.RAW-HASH) && nqp::elems(braw), | |||
nqp::stmts( # second has elems | nqp::stmts( # second has elems | |||
(my \elems := nqp::clone(araw)), | (my \elems := nqp::clone(araw)), | |||
(my \iter := nqp::iterator(braw)), | (my \iter := nqp::iterator(braw)), | |||
nqp::while( # loop over keys of second | nqp::while( # loop over keys of second | |||
skipping to change at line 175 | skipping to change at line 174 | |||
!! nqp::isconcrete(b) | !! nqp::isconcrete(b) | |||
?? nqp::istype(b,Mixy) | ?? nqp::istype(b,Mixy) | |||
?? a.Mix (|) b | ?? a.Mix (|) b | |||
!! nqp::istype(b,Baggy) | !! nqp::istype(b,Baggy) | |||
?? a.Bag (|) b | ?? a.Bag (|) b | |||
!! a.Set (|) b.Set | !! a.Set (|) b.Set | |||
!! a (|) b.Set | !! a (|) b.Set | |||
!! a.Set (|) b | !! a.Set (|) b | |||
} | } | |||
multi sub infix:<(|)>(**@p) { | multi sub infix:<(|)>(+@p) { # also Any | |||
my $result = @p.shift; | my $result := @p.shift; | |||
$result = $result (|) @p.shift while @p; | if @p { | |||
$result | $result := $result (|) @p.shift while @p; | |||
$result | ||||
} | ||||
else { | ||||
$result.Set | ||||
} | ||||
} | } | |||
# U+222A UNION | # U+222A UNION | |||
my constant &infix:<∪> := &infix:<(|)>; | my constant &infix:<∪> := &infix:<(|)>; | |||
# vim: expandtab shiftwidth=4 | # vim: expandtab shiftwidth=4 | |||
End of changes. 2 change blocks. | ||||
5 lines changed or deleted | 9 lines changed or added |