Validate

Validate エフェクトは Either エフェクトと似ているが、失敗をまとめることができる。

import org.atnos.eff._, all._, syntax.all._

  /**
   * スタックの宣言
   */
  type S = Fx.fx1[Validate[String, *]]

  def checkPositiveInt(i: Int): Eff[S, Unit] =
  validateCheck(i >= 0, s"$i is not positive")

  def checkPositiveInts(a: Int, b: Int, c: Int): Eff[S, (Int, Int, Int)] = for {
  _ <- checkPositiveInt(a)
  _ <- checkPositiveInt(b)
  _ <- checkPositiveInt(c)
} yield (a, b, c)

  checkPositiveInts(1, -3, -2).runNel.run

> Left(NonEmptyList(-3 is not positive, -2 is not positive))