00:32 Manifest0 joined 01:32 swaggboi left 01:36 Manifest0 left 01:45 swaggboi joined 03:46 Chanakan5591 joined, Chanakan left 06:39 Tirifto left 06:54 Tirifto joined 08:58 Manifest0 joined 09:58 teatwo joined 09:59 tea3po joined 10:00 teatime left 10:01 teatime joined 10:02 teatwo left 10:04 tea3po left 11:26 Chanakan5591 left 14:36 snonux left 14:37 snonux joined 19:57 teatwo joined 19:59 teatime left
dwinkley thought id quickly pick up raku as another fp language by doing aoc problems but ive literally been stuck for an hour on day 1 part 2. this is the problematic part of my code: @inp.map({ my $parsed = %replace.pairs.reduce( -> $acc, $pair { $acc.subst($pair.key, $pair.value, :g); }, $_); }); the compiler is saying this: Cannot resolve caller reduce(Seq:D: Block:D, Str:D); none of these 20:16
signatures matches: (Any:U: &, *%_ --> Nil) (Any:D: &with, *%_) in block <unit> at main.raku line 19 and i havent been able to find very great documentation on the reduce function for this use case. can anyone help me?
thanks in advance for the help 20:17
antononcube Most likely you have to use |$_ . 20:56
Actually that ($_) is a string -- make sure $_ is a list. 20:57
dwinkley so $_.comb? 21:07
both of these suggestions still give the same error 21:08
ab5tract I would first suggest pulling the operations apart, if possible 21:16
Also,explicitly naming the argument to map instead of using the topic variable can help clarify things 21:17
It might be easier to help if the full code was shared 21:20
Anyway, the error message is stating that the only signature for reduce is a single callable 21:23
librasteve @dwinkley could you provide a gist so that we have some context ...? 21:25
ab5tract *%_ is a bit hard to read but that is a default parameter in (almost) all signatures 21:26
antononcube The first suggestion -- using a slip -- works if $_ is a list/array. 21:39
So, you have/had to use |$_.comb . 21:40
dwinkley of course gist.github.com/dwinkley2/ba2f74aa...4c5cea9d99
librasteve tx!
@dwinkley I am struggling a bit to understand what you are aiming to do - please can you provide an example result maybe? 21:47
dwinkley I want to execute every predefined 'replace' on $_ 21:49
And preferably without mutation
You can ignore the check_str parts 21:50
librasteve oh, ok
i think you need .trans just chacking... 22:01
my %replace2 = %replace.map( { [.key] => [.value] } ); say @inp>>.trans(%replace2); 22:24
this does the job - it seems that .trans needs the key and value of Pairs to be lists to do multicharacter insertions docs.raku.org/routine/trans#(Str)_method_trans 22:26
for @inp -> $inp is rw { for %replace { $inp .= subst( .key, .value ); } say $inp } 22:56