Regarding a recent discussion on flattening hash values. Here are some
posted answers:
>#Konrad Bucheli
> my %hash-with-arrays = a => [1,2], b => [2,3];
{a => [1 2], b => [2 3]}
> %hash-with-arrays.values>>.map({$_}) #makes a List
((1 2) (2 3))
> %hash-with-arrays.values>>.map({$_}).flat
(2 3 1 2)
I left out first line in the example REPL
> my %hash-with-arrays = a => [1,2], b => [3,4], c=>5, d=>[6,[7,8]]
{a => [1 2], b => [3 4], c => 5, d => [6 [7 8]]}
> say gather %hash-with-arrays.values.deepmap: { .take }
(6 7 8 1 2 3 4 5)
> say %hash-with-arrays.values>>[].flat
(6 [7 8] 1 2 3 4 5)
Larry all looks good with the latest email and encoding!
Interpreting %hash-with-arrays.values>>[].flat aka
%hash-with-arrays.values»[].flat
>> is hyperoperator
https://docs.raku.org/language/operators#index-entry-hyper_
<<-hyper_>>-hyper_«-hyper_»-Hyper_operators
and as for [] "it's the postcir
On Tue, Apr 07, 2020 at 09:15:06AM -0700, Larry Wall wrote:
: Maybe if I actually put a Chinese character in like 楽 it will leave it in
UTF-8?
Oops, actually, now that I think about it, 楽 (raku) is a Japanese-only
character.
The Chinese equivalents are traditional 樂 and simplified 乐.
I really d
On Mon, Apr 06, 2020 at 08:04:45PM -0400, yary wrote:
: Larry's answer came through my browser with munged Unicode, it looks like
: this
:
: [image: image.png]
: - with the Chinese character for "garlic" after the word "values"
I wrote the Unicode equivalent of:
%hash-with-arrays.values>>[].
[*] is also a meta prefix op
say [*] 4, 3, 2; # 24
But it also looks exactly the same as the [*] postfix combination of
operators
my @a = 1,2,3;
say @a[*]; # (1 2 3)
There is supposed to be one that looks like [**]
my @b = [1,], [1,2], [1,2,3];
say @b[**]; # (1 1 2 1 2 3)
Question- what am I missing from the below two replies?
Larry's answer came through my browser with munged Unicode, it looks like
this
[image: image.png]
- with the Chinese character for "garlic" after the word "values"
Then Ralph says "[**] will be a wonderful thing when it's implemented" but
a
Oh, you wanna go deep? Why stop at 10 levels?
say gather %hash-with-arrays.values.deepmap: { .take }
No .flat needed, even.
Larry
On Sat, Apr 04, 2020 at 10:59:36PM +0100, Ralph Mellor wrote:
: [**] will be a wonderful thing when it's implemented.
:
: In the meantime, you could maybe use
A microwave is easier:
https://www.google.com/search?q=microwave+garlic+to+remove+skin
[**] will be a wonderful thing when it's implemented.
In the meantime, you could maybe use this as a hack that works to 10
levels deep:
my %hash-with-arrays = a => [1,2], b => [3,4];
sub postfix:<[**]> ($arg)
You can also do a hyper descalarize if you're into that sort of thing:
%hash-with-arrays.values»[].flat
Larry
> On 2 Apr 2020, at 23:49, Konrad Bucheli via perl6-users
> wrote:
> I have a hash with arrays as value. Out of that I wanted to get a flat list
> with all the entries in the value arrays. My first intuitive attempt was to
> use flat, but somehow that only works with an additional map step:
>
11 matches
Mail list logo