pablisco
05/06/2021, 9:05 PMraulraja
05/07/2021, 8:11 AMpablisco
05/07/2021, 8:14 AMsimon.vergauwen
05/07/2021, 8:19 AMreduceOrNull
https://docs.w3cub.com/kotlin/api/latest/jvm/stdlib/kotlin.collections/reduce-or-null
?pablisco
05/07/2021, 8:19 AMreduceOrNull
but with comprehensions for iterating/skipping elements of a list/iterable (gonna make a reversed one for Lists)
I’m still not sure about the name (the hardest thing in programming)simon.vergauwen
05/07/2021, 8:21 AMorNull
in the Kotlin API namingpablisco
05/07/2021, 8:23 AMpartialReduceOrNull
?partialFoldOrNull
to provide an accumulator 🙂partialReduceOrNull
for R?
and without the orNull
with either a kotlin.Result
, Either
or Validated
I’m not 100% sure which would be best. We don’t tend to use kotlin.Result
as exceptions are heavy 🤔
Something like: Either<R, IterationFailure>
may be better and we can always provide an extension to make it a Result
simon.vergauwen
05/07/2021, 9:37 AMEither<X, R>
over R?
unless you have additional information you can share with the consumer about the error. Afaik here only 1 error can occur which is that you request more elements than are available, right?pablisco
05/07/2021, 9:39 AMsimon.vergauwen
05/07/2021, 9:42 AMdata class ReductionFailure(val originalSize: Int, val requestedIndex: Int)
? That is definitely possible but it would also require more state/overhead inside the DSL since you need to keep track of how many times next()
was called etc.pablisco
05/07/2021, 10:44 AM