I was trying to get Option[Author]
from book
in getAuthor
method:
import shapeless.ops.record._
case class Book(title: String, author: Option[Author])
case class Author(name: String)
val book = Book("Types and Programming Languages", Option(Author("Benjamin Pierce")))
val w = Witness('author)
def getAuthor[T1, T2 <: HList, T3](t: T1)(implicit gen: LabelledGeneric.Aux[T1, T2], s: Selector.Aux[T2, w.T, Option[T3]]): s.Out = {
val repr = gen.to(t)
val opt = s.apply(repr)
opt.foreach {
??? // do something
}
opt
}
val author = getAuthor(book)
println(author)
but this code cause following compilation error:
could not find implicit value for parameter s: shapeless.ops.record.Selector.Aux[T2,shapeless.DuckTyping.w.T,Option[T3]] (No field shapeless.DuckTyping.w.T in record T2)
val author = getAuthor(book)
I want to avoid compilation error and specify Option[T]
as Selector#apply
return value.
Can anyone help, please?