Created
September 25, 2016 21:44
-
-
Save n4to4/761a8855ab622d95def66625a6de1775 to your computer and use it in GitHub Desktop.
Using a polymorphic function to extract an object from Options
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
// Using a polymorphic function to extract an object from Options | |
// http://stackoverflow.com/questions/39628022/using-a-polymorphic-function-to-extract-an-object-from-options/39636969#39636969 | |
object Main extends App { | |
import scalaz._, syntax.std.option._ | |
import shapeless._, shapeless.poly.~> | |
val options = 1.some :: "A".some :: 3.5.some :: HNil | |
object uuu extends (Option ~> Id) { | |
def apply[T](l: Option[T]): T = l.get | |
} | |
val z = options.map(uuu) | |
println(z) // 1 :: A :: 3.5 :: HNil | |
/* | |
def foo[F[_, _, _]](f: F[Int, Int, Int]) = f | |
println(foo[Any](1)) // 1 | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment