zio-prelude
zio-prelude copied to clipboard
Turn Validation into ZValidation with extra type parameter
We should add a Log
type parameter (covariant) that appears on successful values (and failures).
Then an operator like ??
(log
) that allows adding something to the log.
sealed trait ZValidation[+W, +E, +A] { self =>
def ?? [W1 >: W](w: W1): ZValidation[W1, E, A] = ???
def log[W1 >: W](w: W1): ZValidation[W1, E, A] = self ?? w
}
object ZValidation {
def log(w: W): ZValidation[W, Nothing, Unit] = ???
}
type Validation[+E, +A] = ZValidation[Nothing, E, A]
Internally the log can be stored in Chunk[W]
in both the success and failure cases.
I will add.
I wonder if we need a free semiring structure like Cause
here to capture the potential parallel and sequential structure of the log.
Couldn't hurt to add that if we package it up nicely, in fact maybe a general data type for such things.