08:00 dakkar joined
Anton Antonov What does this declaration within a class mean: `has $.var0 of Str;` ? Is it the same as `has Str $.var0;` ? 13:34
lizmat yeah, at least the BUILDPLAN for that class looks identical :-) 13:37
Anton Antonov @lizmat Thank you!
What is the most concise way to "transpose" a hash of hashes? I.e. from (h1) `{female => {died => 127, survived => 339}, male => {died => 682, survived => 161}}` to obtain (h2) `{died => {female => 127, male => 682}, survived => {female => 339, male => 161}}`? I can, of course, use for-loop / map, etc., but I strongly suspect there are better solutions... 13:48
lizmat my %h2 = %h1.map: { .key => .value<died> } 13:52
ah, no 13:53
lizmat draws a blank on not using a .map :-) 13:56
gfldex m:``` 14:39
my %h1 = female => {died => 127, survived => 339}, male => {died => 682, survived => 161};
say %h1{*;'died'}:kv;
```
That one needs v6.* to work. Also, this is just the first step. 14:40
gfldex lizmat: this is a usecase for gist.github.com/gfldex/381b402a535...194a25dd96 14:41
the {**}:deepkv case
gfldex m:``` 14:43
use v6.*;
my %h1 = female => {died => 127, survived => 339}, male => {died => 682, survived => 161};
say %h1{*;'died'}:kv;
```
actually, we got fixed dimensions, so we should not need the hyperwhatever 14:47
Nahita what is the meaning of a variable without a twigil declared with `has`? e.g. `class A { has $val }`. 14:49
I saw it in this answer: stackoverflow.com/questions/629688...2#62969222 14:50
I saw it in this answer: stackoverflow.com/a/62969222 14:51
Anton Antonov <@!195453211409121280> With raku(do) version 2021.06 I get `%res{*;'died'} --> (682 127)`, i.e. I cannot use `kv`. 14:52
gfldex <@!694526400488669234> you need to add `use v6.*` to get the .e_PREVIEW, but the june release might also be to old 14:56
m:``` 14:57
my %h1 = female => {died => 127, survived => 339}, male => {died => 682, survived => 161};
say (%h1{*;*}:kv).flat.rotor(3)».[1,0,2]».map({ $^a => $^b => $^c});
```
m:```
use v6.*;
my %h1 = female => {died => 127, survived => 339}, male => {died => 682, survived => 161};
say (%h1{*;*}:kv).flat.rotor(3)».[1,0,2]».map({ $^a => $^b => $^c});
```
Anton Antonov <@!195453211409121280> Ok, thanks -- I was looking into what "rakudo star" means...
gfldex that's how far I got. I don't think we got an easy way to assign that directly to a Hash. At least it gives me an idea what `%h{**} = (survived => male => 161) (died => male => 682) (died => female => 127) (survived => female => 339)` would mean. 14:58
m:``` 15:08
use v6.*;
my %h1 = female => {died => 127, survived => 339}, male => {died => 682, survived => 161};
my %h2;
for (%h1{*;*}:kv).flat.rotor(3)».[1,0,2] -> [ $k1, $k2, $v ] {
%h2{||[$k1, $k2]} = $v;
}
say %h2;
```
there you go :)
I didn't know that `||<key1 key2>` worked. 15:09
<@!694526400488669234> The following blogpost might help to understand what is going on. This is a case where we need to change to order of keys in a deepkey. gfldex.wordpress.com/2021/07/11/co...-addition/ 15:10
15:22 discord-raku-bot left, discord-raku-bot joined 15:23 discord-raku-bot left, discord-raku-bot joined 16:48 dakkar left
Nahita here is another for-loop based solution: 17:01
m:```
my %h1 := {female => {died => 127, survived => 339}, male => {died => 682, survived => 161}};
my %h-new;
for %h1.values.first.keys X %h1.keys -> ($new-key, $current-key) {
%h-new{$new-key}{$current-key} = %h1{$current-key}{$new-key};
}
say %h-new;
```
`%h1.values.first.keys` gets the keys of each inner hash (`died, survived`) and then it is cross producted with the current keys (`female, male`) to help form the transposed hash. 17:03
22:52 Polyinsecure joined 23:15 Polyinsecure left