Skip to content

Commit

Permalink
Complete kleisli docs
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianRaFo committed Mar 21, 2018
1 parent 3affffe commit eac1ddb
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion modules/docs/arrow-docs/docs/docs/datatypes/kleisli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,42 @@ optionIntKleisli.map { output -> output + 1 }.fix().run("1")
```

#### FlatMap
`flatMap` is useful to map the `Kleisli` output into another kleisli

```kotlin:ank
import arrow.data.fix
#### Zip
val optionDoubleKleisli = Kleisli { str: String ->
if (str.toCharArray().all { it.isDigit() }) Some(str.toDouble()) else None
}
optionIntKleisli.flatMap({optionDoubleKleisli},Option.monad()).fix().run("1")
```


#### AndThen
You can use `andThen` to compose with another kleisli

```kotlin:ank
import arrow.data.fix
val optionFromOptionKleisli = Kleisli { number: Int ->
Some(number+1)
}
optionIntKleisli.andThen(optionFromOptionKleisli,Option.monad()).fix().run("1")
```

with another function

```kotlin:ank
optionIntKleisli.andThen({number: Int -> Some(number+1)}, Option.monad()).fix().run("1")
```

or to replace the `Kleisli` result

```kotlin:ank
optionIntKleisli.andThen(Some(0), Option.monad()).fix().run("1")
```


0 comments on commit eac1ddb

Please sign in to comment.