Skip to content

Instantly share code, notes, and snippets.

@divarvel
Last active April 28, 2017 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divarvel/d8de31cdc8d1107e4c06 to your computer and use it in GitHub Desktop.
Save divarvel/d8de31cdc8d1107e4c06 to your computer and use it in GitHub Desktop.
Anorm parser derivation
> compile
[info] Compiling 1 Scala source to /mnt/data/projects/perso/pg-entities/target/scala-2.11/classes...
[error] /mnt/data/projects/perso/pg-entities/src/main/scala/pgentity/automagic/ParserDerivation.scala:59: could not find implicit value for parameter subtypeUnifier: shapeless.ops.hlist.SubtypeUnifier[keys.Out,Symbol]
[error] val parsers = functionList zipApply keys().unifySubtypes[Symbol]
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 1 s, completed 28-Jan-2016 19:35:50
def generateParser[Entity, LHL <: HList, HL <: HList](
implicit labelledGen: LabelledGeneric.Aux[Entity, LHL],
gen: Generic.Aux[Entity, HL],
keys: Keys[LHL],
toParser: FieldToParser[LHL]) = {
val functionList = FieldToParser[labelledGen.Repr].apply()
val parsers = functionList zipApply keys().unifySubtypes[Symbol]
object composeParsers extends Poly2 {
implicit def merge[A, B] = at[RowParser[A], RowParser[B]]((fp: RowParser[A], parseAcc: RowParser[B]) => fp ~ parseAcc)
}
parsers.tail.foldLeft(parsers.head)(composeParsers).map(x => gen.from(hlist(x)))
}
@jto
Copy link

jto commented Jan 28, 2016

Something along the line of:

 def generateParser[Entity, LHL <: HList, HL <: HList, KOut](
    implicit labelledGen: LabelledGeneric.Aux[Entity, LHL],
    gen: Generic.Aux[Entity, HL],
    keys: Keys.Aux[LHL, KOut],
    toParser: FieldToParser[LHL],
    unif: SubtypeUnifier[KOut,Symbol]
)

should do the trick.

@divarvel
Copy link
Author

It needs to unify KOut and keys.Out

@milessabin
Copy link

Looks to me like KOut will equal keys.Out in @jto's fragment.

@etaque
Copy link

etaque commented Apr 28, 2017

Hi, I'm trying to make this work. Did you manage to unify KOut and keys.Out ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment