Catamorphism on the Option.
Catamorphism on the Option. This is identical to fold, but it only has one parameter list, which can result in better type inference in some contexts.
Modify the context F
using transformation f
.
Transform this OptionT[F, A]
into a Nested[F, Option, A]
.
Transform this OptionT[F, A]
into a Nested[F, Option, A]
.
An example where toNested
can be used, is to get the Apply.ap
function with the
behavior from the composed Apply
instances from F
and Option
, which is
inconsistent with the behavior of the ap
from Monad
of OptionT
.
scala> import cats.implicits._ scala> import cats.data.OptionT scala> val ff: OptionT[List, Int => String] = | OptionT(List(Option(_.toString), None)) scala> val fa: OptionT[List, Int] = OptionT(List(Option(1), Option(2))) scala> ff.ap(fa) res0: OptionT[List,String] = OptionT(List(Some(1), Some(2), None)) scala> OptionT(ff.toNested.ap(fa.toNested).value) res1: OptionT[List,String] = OptionT(List(Some(1), Some(2), None, None))
OptionT[F[_], A]
is a light wrapper on anF[Option[A]]
with some convenient methods for working with this nested structure.It may also be said that
OptionT
is a monad transformer forOption
.For more information, see the documentation.