bj0
08/20/2024, 5:20 PMmapOrAccumulate
?Youssef Shoaib [MOD]
08/20/2024, 5:22 PMlist.withIndex().mapOrAccumulate { (index, element) ->
withError({ e: MyErrorType -> e to index }) {
}
}
bj0
08/20/2024, 5:24 PMYoussef Shoaib [MOD]
08/20/2024, 5:26 PMbj0
08/20/2024, 5:27 PMYoussef Shoaib [MOD]
08/20/2024, 5:27 PMPair
bj0
08/20/2024, 5:28 PMYoussef Shoaib [MOD]
08/20/2024, 5:29 PMMyErrorType
here is just whatever error that your code already throwsbj0
08/20/2024, 5:30 PMEither<Any, T>
instead of Either<ErrorType, T>
Youssef Shoaib [MOD]
08/20/2024, 5:36 PMmapOrAccumulate
receiver instead of the withError
onebj0
08/20/2024, 5:56 PMAny
, i just wrapped it in a new error type so I could use my error interfacebj0
08/20/2024, 5:56 PMranges.withIndex().mapOrAccumulate { (idx, range) ->
val low = withError({ IndexedError(idx, it) }) { range.first.parseFreq() }
val high = withError({ IndexedError(idx, it) }) { range.second.parseFreq() }
ensure(low.valueInHz < high.valueInHz) {
IndexedError(idx, InvalidInput("low value must be lower than high value"))
}
low to high
}
bj0
08/20/2024, 5:58 PMIndexedValue<T>