zio-prelude icon indicating copy to clipboard operation
zio-prelude copied to clipboard

Turn Validation into ZValidation with extra type parameter

Open jdegoes opened this issue 4 years ago • 3 comments

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.

jdegoes avatar Aug 07 '20 20:08 jdegoes

I will add.

adamgfraser avatar Aug 07 '20 21:08 adamgfraser

I wonder if we need a free semiring structure like Cause here to capture the potential parallel and sequential structure of the log.

adamgfraser avatar Aug 08 '20 03:08 adamgfraser

Couldn't hurt to add that if we package it up nicely, in fact maybe a general data type for such things.

jdegoes avatar Aug 08 '20 18:08 jdegoes