Created
December 1, 2017 21:03
-
-
Save frosforever/21ff5881690c324382916cba2af80c38 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 shapeless._ | |
import shapeless.ops.hlist | |
object mapper extends Poly1 { | |
implicit def caseOpt[T] = at[Option[T]](_ => Option.empty[T]) | |
} | |
def foo[S, SRep <: HList, O <: HList](s: S)(implicit | |
labelledGeneric: Generic.Aux[S, SRep], | |
map: hlist.Mapper.Aux[mapper.type, SRep, O], | |
i1: Generic.Aux[S, O] | |
) = { | |
i1.from( | |
labelledGeneric.to(s).map(mapper) | |
) | |
} | |
case class Qai(a: Option[String], b: Option[Int]) | |
println { | |
foo(Qai(Some("asdf"), Some(1))) //Qai(None, None) | |
} | |
case class Bar(a: Int, b: Option[Int]) | |
// foo(Bar(1, None)) //Will Not compile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment