Skip to content

Instantly share code, notes, and snippets.

@kubukoz
Last active January 26, 2017 10:50
Show Gist options
  • Save kubukoz/c42d9a3a09aaeec10256bba4094a2cc2 to your computer and use it in GitHub Desktop.
Save kubukoz/c42d9a3a09aaeec10256bba4094a2cc2 to your computer and use it in GitHub Desktop.
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