Youssef Shoaib [MOD]
11/27/2025, 2:53 AMaccumulate dsl doesn't easily allow you to "map" values:
accumulate {
val a by accumulating { raise(42) }
val b by accumulating { a + 1 } // raises here
println("Hello World") // this never runs
}
I don't know if there's really a way to get around this, at least right now with context parameters not being supported for property delegates.
I'm not saying the behaviour is incorrect, either, but just that it'd be more helpful if it worked differently.Youssef Shoaib [MOD]
11/27/2025, 3:05 AMRaiseAccumulate.Value objects directly, then we maybe could do:
accumulate {
val a = accumulating { raise(42) }
val b = accumulating {
a.bind() + 1
}
println("Hello World")
}
context(_: Raise<RaiseAccumulate.Value<Nothing>>)
fun <T> RaiseAccumulate.Value<T>.bind(): T = when (this) {
is RaiseAccumulate.Error -> raise(this)
else -> value
}
I haven't thought through whether that's the right API to expose, though.Youssef Shoaib [MOD]
11/27/2025, 3:11 AMaccumulating simply delay all exceptions, similar to how async behaves. Maybe that's more correct? It'd be kinda surprising, and definitely a behaviour change:
val someOuterRaise: Raise<Unit> = ...
accumulate {
val a by accumulating { someOuterRaise.raise(Unit) }
println("Hello World") // this currently never runs, but it would run under this "proposal"
} // this always raises to someOuterRaise, regardless of this proposal
This behaviour is true for async though. In some ways, accumulating is very similar to async, in fact, an accumulatingAsync would be nice to have, but that's besides the point.Youssef Shoaib [MOD]
11/27/2025, 3:41 AMRaise has taught me anything, it's to be suspicious of any function of the form Raise<T>.foo(..., block: Raise<T>.(...) -> ...) because it's giving special behaviour to only one Raise instance, when maybe you want to give that behaviour to many such instances. A similar situation showed up in the racing DSL, where the solution was to treat RaiseCancellationException in a special way. accumulating is a bit different though, since it doesn't actually take in a Raise, but rather an Accumulate.