Can someone explain why this code compiles and works like a charm:
val a = true :: Some(5) :: true :: HNil
a.select[Some[Int]] // Some(5)
but this one fails:
def foo[HL <: HList](a: HL): Some[Int] = {
a.select[Some[Int]] // fails
}
Implicit not found: shapeless.Ops.Selector[tp, Some[Int]]. You requested an element of type Some[Int], but there is none in the HList tp.
a.select[Some[Int]]
I don't want to pass a instance of Selector.
I also tried:
type tp = Boolean :: Option[Int] :: Boolean :: HNil
def foo(a: tp): Some[Int] = a.select[Some[Int]] // fails
foo(a)
but it failed with a message:
Implicit not found: shapeless.Ops.Selector[tp, Some[Int]]. You requested an element of type Some[Int], but there is none in the HList tp.
a.select[Some[Int]]
How about this:
The full signature of
select
isThere is an implicit parameter
selector
, so you must provide one.