08:12 dakkar joined
Anton Antonov How can I use `reduce` , or similar operation, with initial value? Something like `reduce( $op, $init, $list)`. 08:35
08:36 lizmat_ joined, TempIRCLogger__ left 08:37 lizmat left, TempIRCLogger joined, lizmat_ left, lizmat joined
Morfent m:``` 09:15
use v6;
sub foldl1(&f, @xs) { @xs.reduce: &f }
sub foldl(&f, $init, @xs) { foldl1 &f, ($init, |@xs) }
say foldl &infix:</>, 64, (8, 8);
<@!694526400488669234> 09:16
the `&reduce` with its `+list` parameter might be more readable in some cases 09:17
Anton Antonov <@!210313526928080896> Ok, using my own fold/reduce definition is good. Thanks! 09:18
<@!210313526928080896> Of course, it should have occurred to me to use slip, `($init, |@list)`... 09:20
This statement made read the documentation more carefully around `+list`. So, this works : `‌‌reduce( &infix:<+>, 1..5, 1000)` . 09:33
This statement made read the documentation more carefully around `+list`. So, this works : `‌‌reduce( &infix:<+>, 1..5, 1000)` , i.e. it is what I asked for.
10:30 discord-raku-bot left, discord-raku-bot joined
Nemokosch btw I definitely like this simple sentinel-approach for iterators more than throwing an exception as it is in Python 12:11
when iterating two things together, this is much more comfortable
12:49 codesections joined
By the way 14:19
how do I check whether any of the given iterators reached the end? 14:20
16:05 discord-raku-bot left 16:06 discord-raku-bot joined 16:41 dakkar left
gfldex <@!297037173541175296> WIth `IterationEnd`, which you should never acutally encounter. Iterators are quite internal and not part of the language spec. 21:26
21:29 discord-raku-bot left, discord-raku-bot joined
Nemokosch It's important enough to be able to use iterators actually 21:33
and something that has an implementable interface shouldn't be that internal
codesections Nemokosch#9980, I agree that Iterators aren't **that** internal (and they _are_ well documented/have a stable API, unlike something that genuinely `.is-implementation-detail`). But still gfldex is right that it's pretty rare to need to do much with Iterat**ors**; even when you're implementing your own classes, you can typically implement 22:03
Iterat**able**, and let the Iterator methods use the default implementations.
m: class C does Iterable { has @.inner handles <iterator> }; my $a = C.new: :inner[1,2,3]; say $a.map(* × 2) 22:05
er, do we not have an eval-bot in #raku-beginner ? 22:06
gfldex codesections: the eval bot still only serves from the Discord side of the bridge. 22:07
codesections Aha, fair enough 22:08
Nemokosch I didn't need to _implement_ iterators but I needed to call the given interface myself 22:20
This definitely isn't a taboo in most languages I know. It's not often needed but definitely a legitimate usage. 22:21
if you have a more comfortable way to lazily diff two (essentially) csv files that are ordered in advance, please go ahead, this is the solution I could came up with for Python back in the day and so far I have nothing better 22:23