Created
March 20, 2020 10:45
-
-
Save rohinp/3ad33395d34554bc62199d0b1fd1cc61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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