Created
February 18, 2015 23:27
-
-
Save ryanonsrc/e3a07fe146d58501283b 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
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(gen.to(c)) | |
} | |
} | |
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