diff --git a/src/main/scala/lenthall/validation/Checked.scala b/src/main/scala/lenthall/validation/Checked.scala new file mode 100644 index 0000000..884116b --- /dev/null +++ b/src/main/scala/lenthall/validation/Checked.scala @@ -0,0 +1,15 @@ +package lenthall.validation + +import cats.data.NonEmptyList +import cats.syntax.either._ +import lenthall.Checked + +object Checked { + implicit class ValidCheck[A](val obj: A) extends AnyVal { + def validNelCheck: Checked[A] = obj.asRight[NonEmptyList[String]] + } + + implicit class InvalidCheck(val obj: String) extends AnyVal { + def invalidNelCheck[A]: Checked[A] = NonEmptyList.one(obj).asLeft[A] + } +} diff --git a/src/test/scala/lenthall/validation/CheckedSpec.scala b/src/test/scala/lenthall/validation/CheckedSpec.scala new file mode 100644 index 0000000..c434f16 --- /dev/null +++ b/src/test/scala/lenthall/validation/CheckedSpec.scala @@ -0,0 +1,14 @@ +package lenthall.validation + +import cats.data.NonEmptyList +import org.scalatest.{FlatSpec, Matchers} +import lenthall.validation.Checked._ + +class CheckedSpec extends FlatSpec with Matchers { + behavior of "Checked" + + it should "provide helper methods" in { + 5.validNelCheck shouldBe Right(5) + "argh".invalidNelCheck[Int] shouldBe Left(NonEmptyList.one("argh")) + } +}