Skip to content

Instantly share code, notes, and snippets.

@n4to4
Created September 25, 2016 21:44
Show Gist options
  • Save n4to4/761a8855ab622d95def66625a6de1775 to your computer and use it in GitHub Desktop.
Save n4to4/761a8855ab622d95def66625a6de1775 to your computer and use it in GitHub Desktop.
Using a polymorphic function to extract an object from Options
// 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