Last active
September 12, 2018 13:38
-
-
Save loicdescotte/a35350580358b260965e9c2e6392f6af to your computer and use it in GitHub Desktop.
Cats sequence functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cats.implicits._ | |
| val f = (x: Int) => x+1 | |
| val g = (x: Int) => x+2 | |
| val h = (x: Int) => x+3 | |
| // Cats has an Applicative instance for Function1 so you can traverse/sequence it | |
| val l = List(f, g, h).sequence //l : Function1[Int, List[Int]] | |
| l(1) //List(2, 3, 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment