Created
April 25, 2013 02:26
-
-
Save travisbrown/5457070 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._ | |
type StringTo[X] = String => X | |
case class StringFunctions[H <: HList](functions: H = HNil: HNil) { | |
def addFunction[T](f: StringTo[T]) = StringFunctions[StringTo[T] :: H](f :: functions) | |
def map[H1 <: HList, R](f: H1 => R)(implicit mapped: MappedAux[H1, StringTo, H]) = ??? | |
def map2[T1, T2, R](f: (T1, T2) => R)(implicit ev: H <:< (StringTo[T1] :: StringTo[T2] :: _)) = ??? | |
def apply[S <: HList](strings: S)(implicit zip: ZipApply[H, S]) = zip(functions, strings) | |
} | |
val f1 = (_: String).toInt | |
val f2 = (s: String) => s.toInt + 1 | |
val sum2: (Int :: Int :: HNil) => Int = { case i :: j :: HNil => i + j } | |
val plus: (Int, Int) => Int = { (i, j) => i + j } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And then the following compile:
But not these:
And so on.