Created
February 8, 2014 12:08
-
-
Save milessabin/8882700 to your computer and use it in GitHub Desktop.
Quick demo of shapeless's Comapped /cc @lars_h @jdegoes
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
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
import shapeless._ ; import ops.hlist.Comapped | |
sealed trait Parser[A] | |
case class DummyParser[A]() extends Parser[A] | |
case class AllOf[L <: HList, O <: HList](parsers: L) | |
(implicit val cm: Comapped.Aux[L, Parser, O]) extends Parser[O] | |
// Exiting paste mode, now interpreting. | |
import shapeless._ | |
import ops.hlist.Comapped | |
defined trait Parser | |
defined class DummyParser | |
defined class AllOf | |
scala> AllOf((DummyParser[Int](): Parser[Int]) :: HNil): Parser[Int :: HNil] | |
res0: Parser[shapeless.::[Int,shapeless.HNil]] = AllOf(DummyParser() :: HNil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment