Created
December 12, 2011 14:42
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
1.wrapNel assert_=== NonEmptyList(1) | |
nel(1, 2, 3) assert_=== NonEmptyList(1, 2, 3) | |
1 <:: 1.wrapNel assert_=== NonEmptyList(1, 1) | |
1.wrapNel :::> List(2, 3) assert_=== NonEmptyList(1, 2, 3) | |
List(1, 2) <::: 3.wrapNel assert_=== NonEmptyList(1, 2, 3) | |
1.wrapNel.list assert_=== List(1) | |
1.wrapNel.stream assert_=== Stream(1) | |
1.wrapNel.copure assert_=== 1 |
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
1.success[String] assert_=== Success(1) | |
"Scala".fail[Int] assert_=== Failure("Scala") | |
implicit def ValidationNELEqual[E: Equal, A: Equal]: Equal[ValidationNEL[E, A]] = Equal.ValidationEqual[NonEmptyList[E], A] | |
implicit def ValidationNELShow[E: Show, A: Show]: Show[ValidationNEL[E, A]] = Show.ValidationShow[NonEmptyList[E], A] | |
'z'.successNel[Float] assert_=== Success('z') | |
'Scalaz.failNel[Long] assert_=== Failure(NonEmptyList('Scalaz)) |
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
scala> sealed trait Error | |
defined trait Error | |
scala> case class NumberFormatError(e: NumberFormatException) extends Error | |
defined class NumberFormatError | |
scala> case class ArithmeticError(e: ArithmeticException) extends Error | |
defined class ArithmeticError | |
scala> def f(i: String, l: String): ValidationNEL[Error, Long] = try { | |
| (l.parseLong.liftFailNel <**> i.parseInt.liftFailNel)(_ / _).fail.map2(NumberFormatError).validation | |
| } catch { | |
| case e: ArithmeticException => ArithmeticError(e).failNel | |
| } | |
f: (i: String, l: String)scalaz.Scalaz.ValidationNEL[Error,Long] | |
scala> f("5", "100") | |
res3: scalaz.Scalaz.ValidationNEL[Error,Long] = Success(20) | |
scala> f("5", "1") | |
res4: scalaz.Scalaz.ValidationNEL[Error,Long] = Success(0) | |
scala> f("0", "a") | |
res5: scalaz.Scalaz.ValidationNEL[Error,Long] = Failure(NonEmptyList(NumberFormatError(java.lang.NumberFormatException: For input string: "a"))) | |
scala> f("z", "a") | |
res6: scalaz.Scalaz.ValidationNEL[Error,Long] = Failure(NonEmptyList(NumberFormatError(java.lang.NumberFormatException: For input string: "a"), NumberFormatError(java.lang.NumberFormatException: For input string: "z"))) | |
scala> f("0", "100") | |
res7: scalaz.Scalaz.ValidationNEL[Error,Long] = Failure(NonEmptyList(ArithmeticError(java.lang.ArithmeticException: / by zero))) |
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
'Z'.success[String].lift[Option, Char] assert_=== Success(Option('Z')) | |
1.success[String].liftFailNel assert_=== 1.successNel |
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
100.success[String] | 50 assert_=== 100 | |
"Scala".fail[Int] | 50 assert_=== 50 | |
"Scalaz".fail[Int] ||| (_.size) assert_=== 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment