dave08
11/27/2024, 12:49 PMAlejandro Serrano.Mena
11/27/2024, 1:01 PMval sum = Collector.of(
supply = { 0 },
accumulate = Int::plus
)dave08
11/27/2024, 1:05 PMAlejandro Serrano.Mena
11/27/2024, 1:05 PMdave08
11/27/2024, 1:06 PMdave08
11/27/2024, 1:06 PMfun <A, R, S, T, V> zip( x: Collector<A, R>,
y: Collector<A, S>,
z: Collector<A, T>,
combine: suspend (R, S, T) -> V
): Collector<A, V>Alejandro Serrano.Mena
11/27/2024, 1:06 PMAlejandro Serrano.Mena
11/27/2024, 1:07 PMdave08
11/27/2024, 1:08 PMAlejandro Serrano.Mena
11/27/2024, 1:09 PMzip something that adds and something that counts, you get a tuple with the addition and the length at the enddave08
11/27/2024, 1:11 PMdave08
11/27/2024, 1:11 PMAlejandro Serrano.Mena
11/27/2024, 1:12 PMAlejandro Serrano.Mena
11/27/2024, 1:12 PMIterable<A>, and then execute the second on the result of the first onedave08
11/27/2024, 1:12 PMdave08
11/27/2024, 1:13 PMdave08
11/27/2024, 1:13 PMdave08
11/27/2024, 1:13 PMAlejandro Serrano.Mena
11/27/2024, 1:14 PMSequence or Flow, `Collector`s are for getting a single value at the end (like fold or reduce)dave08
11/27/2024, 1:18 PMCharacteristics ? It seems like Collector.of would still need to specify one, no? I'm not too sure what they're needed for here... (w/o going in to the source code...).
Another point is when would we use something other than NonSuspending collectors? I'm having a bit of trouble picturing when something should be a collector, or just be done in the lambda producing the result...dave08
11/27/2024, 1:20 PMCollectors help build complex computations ---over sequences of values---, guaranteeing that those values are consumed only once.Which is I guess why I was expecting "after the other"...
dave08
11/27/2024, 1:23 PMparCollect() ... which confuses me a bit now, since anyways one should be using flows for this?dave08
11/27/2024, 1:24 PMAlejandro Serrano.Mena
11/27/2024, 1:28 PMfold or reduce. For example, sum , max or size are examples of collectors
Imagine that you want to obtain the sym and the maximum of a list, if you do
list.sum() to list.max()
you are iterating over the list twice. With collectors you can easily create something which does it in a single go
val collector = sumCollector.zip(maxCollector, ::Pair)
list.collect(collector)dave08
11/27/2024, 1:29 PMAlejandro Serrano.Mena
11/27/2024, 1:30 PMdave08
11/27/2024, 1:31 PMdave08
11/27/2024, 1:31 PMAlejandro Serrano.Mena
11/27/2024, 1:33 PMparCollect is about executing the accumulation in parallel, for example you can sum a list in that waydave08
11/27/2024, 1:34 PMAlejandro Serrano.Mena
11/27/2024, 1:34 PMdave08
11/27/2024, 1:35 PMdave08
11/27/2024, 1:57 PMzip(take(10) + mapFirstTen, drop(10) + mapLastFive, ::combineList)dave08
11/27/2024, 2:58 PMAlejandro Serrano.Mena
11/27/2024, 8:29 PMdave08
11/28/2024, 10:40 AMA mutable reduction operation that accumulates input elements into a mutable result container, optionally transforming the accumulated result into a final representation after all input elements have been processed. Reduction operations can be performed either sequentially or in parallel.
Examples of mutable reduction operations include: accumulating elements into a `Collection`; concatenating strings using a `StringBuilder`; computing summary information about elements such as sum, min, max, or average; computing "pivot table" summaries such as "maximum valued transaction by seller", etc. The classalso, there's no example or explanation for parCollect()...provides implementations of many common mutable reductions.Collectors
dave08
11/28/2024, 10:41 AMCollectors also have a set of characteristics, such as, that provide hints that can be used by a reduction implementation to provide better performance.Collector.Characteristics.CONCURRENT
dave08
11/28/2024, 10:41 AM