Skip to content

Instantly share code, notes, and snippets.

@nafg
Created July 3, 2012 21:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nafg/3043168 to your computer and use it in GitHub Desktop.
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