Slide 21
Slide 21 text
sequence, traverse
scala> import cats.implicits._
scala> (List(Some(1), Some(2)): List[Option[Int]]).sequence
res0: Option[List[Int]] = Some(List(1, 2))
scala> (List(Some(1), None): List[Option[Int]]).sequence
res1: Option[List[Int]] = None
scala> (Some(List(1,2,3)): Option[List[Int]]).sequence
res2: List[Option[Int]] = List(Some(1), Some(2), Some(3))
scala> (None: Option[List[Int]]).sequence
res3: List[Option[Int]] = List(None)
- 2ॏʹแ·ΕͨMonadͷॱ൪Λͻͬ͘Γฦ͢