First for your last question—you need to conclude the list with HNil
, not HList
. So if for example we have the following:
def function1(s: String) = "foo " + s
def function2(s: String) = s.toInt
def function3(s: String) = s + " bar"
We'd write:
val list = function1 _ :: function2 _ :: function3 _ :: HNil
Since ::
is like the cons operator that you'll find in the Scala standard library (and other languages) in that it takes its first argument (an item) and prepends it to its second (a list).
Now for your first question. Given the HList
I just defined, we could write the following:
val obj = "13"
object mapFunc extends Poly1 {
implicit def funcTo[T] = at[String => T](f => f(obj))
}
And then:
scala> (list map mapFunc) == "foo 13" :: 13 :: "13 bar" :: HNil
res0: Boolean = true
The key is that you need to represent the fact that the case applies when the map element is a function from a string (or whatever your object type is) to something.