This repository has been archived by the owner on Jan 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
} | ||
} |