Skip to content

Commit

Permalink
Add types in the Kleisli code sample for composition (#2165)
Browse files Browse the repository at this point in the history
This makes it easier for the reader to follow the flow of the types.
  • Loading branch information
jcranky authored and Luka Jacobowitz committed Feb 6, 2018
1 parent df732bc commit d228e95
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions docs/src/main/tut/datatypes/kleisli.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@ Returning to our earlier example:
// Bring in cats.FlatMap[Option] instance
import cats.implicits._
val parse = Kleisli((s: String) => if (s.matches("-?[0-9]+")) Some(s.toInt) else None)
val parse: Kleisli[Option,String,Int] =
Kleisli((s: String) => if (s.matches("-?[0-9]+")) Some(s.toInt) else None)
val reciprocal = Kleisli((i: Int) => if (i != 0) Some(1.0 / i) else None)
val reciprocal: Kleisli[Option,Int,Double] =
Kleisli((i: Int) => if (i != 0) Some(1.0 / i) else None)
val parseAndReciprocal = reciprocal.compose(parse)
val parseAndReciprocal: Kleisli[Option,String,Double] =
reciprocal.compose(parse)
```

`Kleisli#andThen` can be defined similarly.
Expand Down

0 comments on commit d228e95

Please sign in to comment.