Slackbot
03/05/2020, 1:22 PMmarstran
03/05/2020, 1:29 PMscan
in Scala, Haskell and other functional languages. So Python seems to be the odd one out actually :Psimon.vergauwen
03/05/2020, 1:40 PMscan
is also used in many Java libraries for this operator.Fleshgrinder
03/05/2020, 1:49 PMZach Klippenstein (he/him) [MOD]
03/05/2020, 2:58 PMreduce
is to fold
what scanReduce
is to scan
. Given that, it would make sense to me to rename reduce
to foldReduce
, but reduce
is already an established name and so it’s too late to rename it (and already implies fold
in other languages as well anyway).Fleshgrinder
03/05/2020, 3:15 PM@ExperimentalStdlibApi
and can be renamed. I recommend you to create a bug report at https://youtrack.jetbrains.com/issues/KT and with a PR https://github.com/JetBrains/kotlin where you change the name directly to what you think is best. I cannot tell how likely it is that you will be heard, so don't get your hopes up, but this will give you most leverage.Fleshgrinder
03/05/2020, 3:16 PMscan
and scanReduce
(the others are BC constant forever).ilya.gorbunov
03/05/2020, 3:20 PMscan...
naming is following:
for each aggregation function, e.g. fold
, reduce
, sum
, max
etc, we can get its scanning variant by adding the prefix "scan": scanReduce
, scanSum
, scanMax
. The only exception is made for fold
, which seems to be so common that scanFold
cuts down to just scan
.
https://youtrack.jetbrains.com/issue/KT-7657#focus=streamItem-27-3520154.0-0simon.vergauwen
03/05/2020, 4:08 PMfold
and reduce
are not the same,as foldl
requires an empty value.
So I’ve always seen reduce
as foldl1
from Haskell, and I think Kotlin has a better name for it than Haskell in that regard.simon.vergauwen
03/05/2020, 4:09 PMsimon.vergauwen
03/05/2020, 4:09 PMFleshgrinder
03/05/2020, 4:22 PMFleshgrinder
03/05/2020, 4:23 PMsimon.vergauwen
03/05/2020, 4:25 PMpoohbar
04/02/2020, 7:06 PMscan
which sounds cool.
😎poohbar
04/02/2020, 7:09 PMCody Engel
04/03/2020, 3:14 PMCody Engel
04/03/2020, 3:33 PMCody Engel
04/03/2020, 3:48 PMaccumulate
making sense, although I wonder if that would be confusing with reduce
as well. Reduce has an accumulator function, but I guess accumulate is a more primitive reduce so could also make sense.Cody Engel
04/03/2020, 3:58 PMRuckus
04/03/2020, 4:37 PMscanFold
function for consistency, and then just have scan
be an alias for ease of use? (Like firstOrNull
and find
)louiscad
04/03/2020, 5:21 PMrunningFold
and runningReduce
or rollingFold
and rollingReduce
I was suggested on Reddit (https://old.reddit.com/r/Kotlin/comments/ftnvzd/stop_scan_and_scanreduce_before_its_too_late/)Cody Engel
04/03/2020, 5:35 PMCody Engel
04/03/2020, 6:01 PMCody Engel
04/03/2020, 7:01 PMilya.gorbunov
04/14/2020, 5:32 PMscanReduce
.
scan
will remain as a synonym for runningFold
https://youtrack.jetbrains.com/issue/KT-38060#focus=streamItem-27-4087852.0-0jordigarcl
06/15/2020, 2:24 PMreduce
/ scanReduce
and get the final result as a Flow
(if that even makes sense)?jordigarcl
06/15/2020, 2:25 PMscanReduce
does return flow but emits all intermediate values, and reduce
emits final value but not wrapped in a FlowZach Klippenstein (he/him) [MOD]
06/15/2020, 2:29 PMasFlow()
) then perform the reduce on the flow. Flow has scan
and reduce
operators, no scanReduce
, but you could file a feature request or just write your own version.marstran
06/15/2020, 2:43 PMscanReduce
on Flow
as well. Although I guess it will be deprecated soon and replaced by runningReduce
: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/scan-reduce.htmljordigarcl
06/15/2020, 2:43 PMZach Klippenstein (he/him) [MOD]
06/15/2020, 2:48 PMJoseF
06/15/2020, 2:51 PMFlow hasYes, but it emits the intermediate resultsscan
andandreduce
reduce
consumes the flow to give you the value. I think what is missing is something such as (http://reactivex.io/documentation/operators/reduce.html)
public suspend inline fun <T, R> Flow<T>.fold(
crossinline operation: suspend (acc: R, value: T) -> R
): Flow<R>
instead of
public suspend fun <S, T : S> Flow<T>.reduce(operation: suspend (accumulator: S, value: T) -> S): S