Re: Rewrite using map? Trasformation array into hash of hash

2014-06-14 Thread Kamil Kułaga
Dear Timo. So .categorize and .classify wil always end with list on leaves of produced tree? Ok I can live with that :) On Sat, Jun 14, 2014 at 12:30 PM, wrote: > Dear Kamil, > > > On 06/13/2014 10:24 PM, Kamil Kułaga wrote: >> my %h = categorize({map {[.a , .b]}, $_},@array); > > I think the p

Re: Rewrite using map? Trasformation array into hash of hash

2014-06-14 Thread timo
Dear Kamil, On 06/13/2014 10:24 PM, Kamil Kułaga wrote: > my %h = categorize({map {[.a , .b]}, $_},@array); I think the problem is that categorize will call your inner code block for every item in the @array. Then you map your {[.a, .b]} over that item, so you end up with a single-item list as a

Re: Rewrite using map? Trasformation array into hash of hash

2014-06-13 Thread Kamil Kułaga
Dear Timo, I'm almost done with categorize. I stole similar example from rakudo tests but I can't get rid off array on end. If I remove from map [] it stops working. PS. I barely understand code I wrote anyway :) $ perl6 ~/xx.pl [A.new(a => "a", b => "22")] Reference A.new(a => "a", b => "

Re: Rewrite using map? Trasformation array into hash of hash

2014-06-13 Thread Elizabeth Mattijsen
On 13 Jun 2014, at 12:36, Kamil Kułaga wrote: > I was wondering whether following code can be rewritten using map/grep > construct. > > >class A { > has $.a; > has $.b; > } > > > my @array= ( > A.new(a=>'a', b=>'11'), > A.new(a=>'a', b=>'22'), > A.new(a=>'v', b=>'33')

Re: Rewrite using map? Trasformation array into hash of hash

2014-06-13 Thread timo
On 06/13/2014 08:15 PM, Kamil Kułaga wrote: > Ok got it. But solution is neither more readable nor faster (IMHO only > -> I didn't benchmark it) > > > class A { has $.a; has $.b }; > my @array = A.new(a=>'a', b=>'11'), > A.new(a=>'a', b=>'22'), > A.new(a=>'v', b=>'33'), > A.new(a=>'w',

Re: Rewrite using map? Trasformation array into hash of hash

2014-06-13 Thread Kamil Kułaga
Ok got it. But solution is neither more readable nor faster (IMHO only -> I didn't benchmark it) class A { has $.a; has $.b }; my @array = A.new(a=>'a', b=>'11'), A.new(a=>'a', b=>'22'), A.new(a=>'v', b=>'33'), A.new(a=>'w', b=>'44'), A.new(a=>'v', b=>'55'); my %h = @array.map({

Re: Rewrite using map? Trasformation array into hash of hash

2014-06-13 Thread Kamil Kułaga
Hi Tobias, Almost. At least at my rakudo creates list of hash of hash and loses data while converting to hash: ("a" => "11" => A.new(a => "a", b => "11"), "a" => "22" => A.new(a => "a", b => "22"), "v" => "33" => A.new(a => "v", b => "33"), "w" => "44" => A.new(a => "w", b => "44"), "v" => "55" =

Re: Rewrite using map? Trasformation array into hash of hash

2014-06-13 Thread Tobias Leich
Hi, like that? class A { has $.a; has $.b }; my @array = A.new(a=>'a', b=>'11'), A.new(a=>'a', b=>'22'), A.new(a=>'v', b=>'33'), A.new(a=>'w', b=>'44'), A.new(a=>'v', b=>'55'); say @array.map({ .a => .b => $_ }) OUTPUT«"a" => "11" => A.new(a => "a"

Rewrite using map? Trasformation array into hash of hash

2014-06-13 Thread Kamil Kułaga
Hi, I was wondering whether following code can be rewritten using map/grep construct. class A { has $.a; has $.b; } my @array= ( A.new(a=>'a', b=>'11'), A.new(a=>'a', b=>'22'), A.new(a=>'v', b=>'33'), A.new(a=>'w', b=>'44'), A.new(a=>'v', b=>'55') );