Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
trait QId; trait QSection; trait QProjectType; trait QName
trait QFriendlyName; trait QDescription; trait QCode; trait QAnswers
case class Answer(text: String)
object QuestionTypes {
type FormQuestionId = Long @@ QId
type Section = String @@ QSection
type ProjectType = String @@ QProjectType
type Name = String @@ QName
type FriendlyName = String @@ QFriendlyName
type Description = String @@ QDescription
type Code = Option[Int] @@ QCode
type Answers = Seq[Answer] @@ QAnswers
def extract[A] = new {
def from[C, Repr <: HList](c: C)(implicit
gen: Generic.Aux[C, Repr],
sel: Selector[Repr, A]
) = sel(
import QuestionTypes._
case class Question (
id: FormQuestionId,
section: Section,
projectType: ProjectType,
name: Name,
friendlyName: FriendlyName,
description: Description,
code: Code,
answers: Answers
// given a question of type Question
import QuestionTypes._
val x = extract[Answers].from(question)
// x is of type sel.type#Out, and I would like to get the answers array instead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment