I was just introduced to BQN, recently. While it won't be my first choice of language until I understand it a lot more, it does provide an interesting insight into all things Listy.
So I thought I might grab some low hanging fruit and bring some of that BQN goodness into Raku, a language that I -am- using on the daily.
Here's an implementation for the Range operator (↕):
multi sub prefix:<↕>(List() $l) {
my @a = [X]( |$l.map({ 0..$_ }) );
+@a == 1 ?? @a.head !! @a
};
We're doing a bit of optimization on that last line that will become aparent in our next example:
say ↕5 # (0 1 2 3 4)
Without that last line, it would have been ((0 1 2 3 4))
which would have not been orthogonal to the rest of the results.
Here's a better example:
say ↕(1,2) # [(0 0) (0 1) (0 2) (1 0) (1 1) (1 2)]
And this should work for an arbitrary list size, so
.say for ↕(1, 2, 2, 5)
Will do what you expect and print out the following:
(0 0 0 0)
(0 0 0 1)
(0 0 0 2)
(0 0 0 3)
(0 0 0 4)
(0 0 0 5)
(0 0 1 0)
(0 0 1 1)
(0 0 1 2)
(0 0 1 3)
(0 0 1 4)
(0 0 1 5)
(0 0 2 0)
(0 0 2 1)
(0 0 2 2)
(0 0 2 3)
(0 0 2 4)
(0 0 2 5)
(0 1 0 0)
(0 1 0 1)
(0 1 0 2)
(0 1 0 3)
(0 1 0 4)
(0 1 0 5)
(0 1 1 0)
(0 1 1 1)
(0 1 1 2)
(0 1 1 3)
(0 1 1 4)
(0 1 1 5)
(0 1 2 0)
(0 1 2 1)
(0 1 2 2)
(0 1 2 3)
(0 1 2 4)
(0 1 2 5)
(0 2 0 0)
(0 2 0 1)
(0 2 0 2)
(0 2 0 3)
(0 2 0 4)
(0 2 0 5)
(0 2 1 0)
(0 2 1 1)
(0 2 1 2)
(0 2 1 3)
(0 2 1 4)
(0 2 1 5)
(0 2 2 0)
(0 2 2 1)
(0 2 2 2)
(0 2 2 3)
(0 2 2 4)
(0 2 2 5)
(1 0 0 0)
(1 0 0 1)
(1 0 0 2)
(1 0 0 3)
(1 0 0 4)
(1 0 0 5)
(1 0 1 0)
(1 0 1 1)
(1 0 1 2)
(1 0 1 3)
(1 0 1 4)
(1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