Skip to content

Commit

Permalink
Simplify Kleisli example
Browse files Browse the repository at this point in the history
Amended second instance of parseAndReciprocal to use the same functions as in the earlier example.
  • Loading branch information
RawToast committed Apr 4, 2017
1 parent 43d205f commit 16149ed
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/src/main/tut/datatypes/kleisli.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ Returning to our earlier example:
// Bring in cats.FlatMap[Option] instance
import cats.implicits._
val parse = Kleisli((s: String) => try { Some(s.toInt) } catch { case _: NumberFormatException => None })
val parse = Kleisli((s: String) => if (s.matches("-?[0-9]+")) Some(s.toInt) else None)
val reciprocal = Kleisli((i: Int) => if (i == 0) None else Some(1.0 / i))
val reciprocal = Kleisli((i: Int) => if (i != 0) Some(1.0 / i) else None)
val parseAndReciprocal = reciprocal.compose(parse)
```
Expand Down

0 comments on commit 16149ed

Please sign in to comment.