Skip to content

Instantly share code, notes, and snippets.

@rohinp
Created March 20, 2020 10:45
Show Gist options
  • Save rohinp/3ad33395d34554bc62199d0b1fd1cc61 to your computer and use it in GitHub Desktop.
Save rohinp/3ad33395d34554bc62199d0b1fd1cc61 to your computer and use it in GitHub Desktop.
import cats.Monad
import cats.implicits._
/*
Interesting to note that if the parametic type is F[A] and your function is expecting F[F[A]]
Then the implicit function as used in the below function works like a charm
It tells scala compiler to use F[F[A]] the implicit is provided by scala itself you don't need to implement
*/
implicit class SomeOps[F[_], A](v:F[A]){
def myflatten[B](implicit M:Monad[F], view: F[A] => F[F[B]]): F[B] = M.flatten(view(v))
}
println(Option(Option(3)).myflatten)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment