Scalaz turns nested existential / validation mono-whatevers-nads around pre-applicative construction

I have the following:

gt.map(_.singleVal) |@| lt.map(_.singleVal)

They have a type Option(Validation(T)), but they must beValidation(Option(T))

It is normal when something does not exist, but it is not normal for what exists to be invalid. In other words, I would like to be Noneinterpreted asSuccess(None)

This seemed to me very common. Is there any sugar in the scalp?

+4
source share
1 answer

, Validation(T) - ValidationNel[Throwable, T], Validation[T] -, Validation[E, T] , E .

, , , traverse ( traverseU, ). , :

scala> case class Foo(singleVal: ValidationNel[Throwable, String])
defined class Foo

scala> val x = some(Foo("hey".success))
x: Option[Foo] = Some(Foo(Success(hey)))

scala> val y = none[Foo]
y: Option[Foo] = None

scala> println(x.traverseU(_.singleVal))
Success(Some(hey))

scala> println(y.traverseU(_.singleVal))
Success(None)

, M traverse, N , M[A] N[M[B]] A => N[B] traverse (. ).

+7

All Articles