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') ); my

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, b = 11) a = 22 =

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 = A.new(a = v, b = 55)).list.item On Fri, Jun 13,

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({ my

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', b='44'),

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 teodoz...@gmail.com 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',