Another set of questions about the new `accumulate...
# arrow
u
Another set of questions about the new
accumulate
DSL: 1. The DSL lets me use the "normal"
ensure
and
ensureNotNull
calls inside an
accumulate
block. Will the resulting errors be accumulated, or do I need to use
ensureOrAccumulate
resp.
ensureNotNullOrAccumulate
? What is the difference between these two approaches? 2. If I do the following in an
accumulate
block, the type checker ist happy:
Copy code
accumulate{
  val a = doSomething().bindOrAccumulate()
  val b = doSomethingElse(a).bindOrAccumulate()
  ConstructType(a, b)
}
That is,
b
might depend on
a
. This is different than the typical applicative block, where only the result may depend on the individual bound results. Does the above work? Does the block short-circuit if a result is needed downstream and otherwise keeps on accumulating?
y
1. The normal calls will still
raise
immediately. The difference is that when you use an
XOrAccumulate
version, you are saying that the rest of the
accumulate
block doesn't care whether that condition is false or not. 2. The type checker isn't happy because
bindOrAccumulate
returns
RaiseAccumulate.Value
, which is basically an `Option`(kind of). We have explicit support for this though simply by using delegation:
Copy code
accumulate {
  val a by doSomething().bindOrAccumulate()
  doSomethingThatMightAccumulate()
  val b by doSomethingElse(a).bindOrAccumulate()
  // if a had an error, the next lines won't run, and `accumulate` would've raised a's error, along with any accumulated error from doSomethingThatMightAccumulate
  doAThirdThing()
  ConstructType(a, b)
  // if b had an error, the next line won't run, and its error would've been raised, alongside any accumulated error from doAThirdThing and doSomethingThatMightAccumulate
  doAFourthThing
}
👍 1
u
Thanks, that is very helpful!