Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import scala.concurrent.Future
import scala.language.higherKinds
import scalaz.Functor
/**
* Created by kubukoz on 25/01/2017.
*/
object ComposedFunctors {
implicit class ComposedMapOps[F[_], G[_], T](val functor: F[G[T]]) extends AnyVal {
def cmap[U](f: T => U)(implicit G: Functor[G], F: Functor[F]): F[G[U]] = (F compose G).map(functor)(f)
}
//sample
import scalaz.std.scalaFuture._
import scalaz.std.option._
import scala.concurrent.ExecutionContext.Implicits.global
val x: Future[Option[Int]] = Future(Option(5)).cmap(_ + 5)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment