Skip to content

Commit

Permalink
Update: docs - either.md: fix leftMap
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-lee committed Dec 30, 2021
1 parent 8838d64 commit c391e74
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions website/docs/types/either.md
Expand Up @@ -132,6 +132,31 @@ Either.<String, Integer>right(5) // Either<String, Integer> = Right(5)
.flatMap(this::bar); // Either<String, Integer> = Left("bar can't take an int less than 100. [n: 10]")
```

### `Either.leftMap`
If you want to change the left value, you can use `map` to do it.

```java
import j8plus.types.Either;

public class MyError {
public final String message;
public MyError(final String message) {
this.message = message;
}

@Override
public String toString() {
return "MyError(message=" + message + ")";
}
}

final Either<String, Integer> errorMsgOrNum = Either.left("Error message");
// Either<String, Integer> = Either.Left(Error message)

errorMsgOrNum.leftMap(err -> new MyError(err));
// Either<MyError, Integer> = Either.Left(MyError(message=Error message))
```

### `Either.swap`


Expand Down

0 comments on commit c391e74

Please sign in to comment.