Skip to content
This repository has been archived by the owner on Jan 25, 2018. It is now read-only.

Commit

Permalink
add some checked helpers (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
Horneth committed Sep 21, 2017
1 parent f5f7f86 commit 9d9a747
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/scala/lenthall/validation/Checked.scala
Original file line number Diff line number Diff line change
@@ -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]
}
}
14 changes: 14 additions & 0 deletions src/test/scala/lenthall/validation/CheckedSpec.scala
Original file line number Diff line number Diff line change
@@ -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"))
}
}

0 comments on commit 9d9a747

Please sign in to comment.