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 e094321
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions docs/src/main/tut/datatypes/ior.md
Original file line number Diff line number Diff line change
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("Can't be empty").leftIor

This comment has been minimized.

Copy link
@peterneyens

peterneyens Sep 15, 2017

Collaborator

These need to be Nel.one again right?

This comment has been minimized.

Copy link
@LukaJCB

LukaJCB Sep 15, 2017

Member

Indeed, not sure what I was thinking 😄

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("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 e094321

Please sign in to comment.