Skip to content

Commit

Permalink
Add note to IorNel
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Jacobowitz committed Sep 15, 2017
1 parent fab1ea3 commit 01aa2f0
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions docs/src/main/tut/datatypes/ior.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def map[B, C](fa: A Ior B)(f: B => C): A Ior C
We can create `Ior` values using `Ior.left`, `Ior.right` and `Ior.both`:

```tut
import cats.data.Ior
import cats.data._
val right = Ior.right[String, Int](3)
Expand Down Expand Up @@ -60,7 +60,7 @@ case class User(name: Username, pw: Password)
def validateUsername(u: String): Failures Ior Username = {
if (u.isEmpty)
Ior.leftNel("Can't be empty")
Nel.one("Can't be empty").leftIor
else if (u.contains("."))
Ior.both(Nel.one("Dot in name is deprecated"), Username(u))
else
Expand All @@ -69,7 +69,7 @@ def validateUsername(u: String): Failures Ior Username = {
def validatePassword(p: String): Failures Ior Password = {
if (p.length < 8)
Ior.leftNel("Password too short")
Nel.one("Password too short").leftIor
else if (p.length < 10)
Ior.both(Nel.one("Password should be longer"), Password(p))
else
Expand Down Expand Up @@ -103,6 +103,18 @@ validateUser("john.doe", "password").fold(
(warnings, user) => s"Warning: ${user.name.value}; The following warnings occurred: ${warnings.show}"
)
```
Similar to [Validated](validated.html), there is also a type alias for using a `NonEmptyList` on the left side.

```tut:silent
type IorNel[B, A] = Ior[NonEmptyList[B], A]
```


```tut
val left: IorNel[String, Int] = Ior.leftNel("Error")
```


Expand Down

0 comments on commit 01aa2f0

Please sign in to comment.