Should it mutate or not? YES!
On Discord Hydrazer was looking for a list concatenation operator. That leaves the question if it should mutate like Array.push
or return a new list of Slip
s.
sub infix:«|<<»(\a, \e) {
Proxy.new(FETCH => method { |a, |e },
STORE => method (\e) {})
but role { method sink { a.push: e } };
}
my @a = 1,2,3;
@a |<< 4;
dd @a;
my @b = @a |<< 5;
dd @a, @b;
In sink-context returning a new list would not make sense. With a Proxy
that provides a sink
-method we can answer the question with “YES!”.
This made me wonder if Proxy
should have the optional argument SINK
. Right now there is no way to define containers in pure Raku. Even with subclassing we would have to decent into nqp-land. As newdisp has shown, it tends to be quite brittle to make modules depend on use nqp;
`.
Categories: Raku
Comments (0)
Trackbacks (1)
Leave a comment
Trackback
-
November 8, 2021 at 20:572021.45 Two Commas – Rakudo Weekly News