Created
March 22, 2019 15:07
-
-
Save izeigerman/5a554b1f686260ed287011592359a34a 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
trait Flattanable[F[_]] { | |
def flatten[A](ff: F[F[A]]): F[A] | |
} | |
object Flattanable { | |
implicit def optionFlattanable: Flattanable[Option] = new Flattanable[Option] { | |
override def flatten[A](ff: Option[Option[A]]): Option[A] = ff match { | |
case Some(Some(v)) => Some(v) | |
case _ => None | |
} | |
} | |
def apply[A[_]: Flattanable]: Flattanable[A] = implicitly[Flattanable[A]] | |
} | |
// This one works | |
val fltn: Flattanable[Option] = Flattanable.optionFlattanable | |
// This one one works too | |
val fltn2: Flattanable[Option] = Flattanable[Option] | |
// This expression is invalid | |
val fltn3: Flattanable[Option] = Flattanable[Option[_]] | |
// This expression is invalid too | |
def fltn4[A]: Flattanable[Option[A]] = Flattanable[Option[A]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment