j <- Maybe.just(2) } yield i + j // i <- Maybe.just(1) // ^ // On line 2: error: value flatMap is not a member of Maybe[Int] // j <- Maybe.just(2) // ^ // On line 3: error: value map is not a member of Maybe[Int]
Maybe[B]): Maybe[B] = this match { case Just(a) => f(a) case Empty() => Empty() } // デフォルト実装 def map[B](f: A => B): Maybe[B] = flatMap(a => Maybe.pure(f(a))) } case class Just[A](a: A) extends Maybe[A] case class Empty[A]() extends Maybe[A]
A] = Reader(_ => a) } final case class Reader[R, A](run: R => A) { def flatMap[B](f: A => Reader[R, B]): Reader[R, B] = Reader(r => f(run(r)).run(r)) def map[B](f: A => B): Reader[R, B] = flatMap(a => Reader.pure(f(a))) }