Created
July 3, 2012 21:11
-
-
Save nafg/3043168 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
object Test extends App { | |
case class Item[A, B](get: A => B, apply: B => Unit) | |
def hlist[A] = | |
Item((_: A) => 73, println) :: | |
Item((_: A) => "hello", println) :: | |
Item((_: A) => false, println) :: | |
HNil | |
class Combine[A] extends Poly2 { | |
implicit def x[T <: HList, B] = at[A => T, Item[A, B]]((aggFunc: A => T, item: Item[A, B]) => { a: A => item.get(a) :: aggFunc(a) }) | |
} | |
object combine extends Combine[Double] | |
val items = hlist[Double] | |
val f1 = items.foldLeft((_: Double) => HNil)(combine) | |
implicitly[f1.type <:< (Double => (Boolean :: String :: Int :: HNil))] | |
val res = f1(32.0) | |
implicitly[res.type <:< (Boolean :: String :: Int :: HNil)] | |
assert(res == (false :: "hello" :: 73 :: HNil)) | |
object apply extends Poly1 { | |
implicit def default[T] = at[Item[_, T]](_.apply) | |
} | |
val zipped = items zip res.reverse | |
implicitly[zipped.type <:< ((Item[Double, Int], Int) :: (Item[Double, String], String) :: (Item[Double, Boolean], Boolean) :: HNil)] | |
//res map apply | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment