Converting Map[String,Any] to a case class using Shapeless

Here’s an off-the-cuff, mostly untested solution. First for the type class: import shapeless._, labelled.{ FieldType, field } trait FromMap[L <: HList] { def apply(m: Map[String, Any]): Option[L] } And then the instances: trait LowPriorityFromMap { implicit def hconsFromMap1[K <: Symbol, V, T <: HList](implicit witness: Witness.Aux[K], typeable: Typeable[V], fromMapT: Lazy[FromMap[T]] ): FromMap[FieldType[K, V] :: T] … Read more

Limits of Nat type in Shapeless

I will attempt one myself. I will gladly accept a better answer from Travis Brown or Miles Sabin. Nat can currently not be used to represent large numbers In the current implementation of Nat, the value corresponds to the number of nested shapeless.Succ[] types: scala> Nat(3) res10: shapeless.Succ[shapeless.Succ[shapeless.Succ[shapeless._0]]] = Succ() So to represent the number … Read more

Unable to map on HList

There’s an easy fix: just define your function as an object instead of a val: object f extends (({ type O2[+A] = (Option[A], Option[A]) })#O2 ~> Option) { def apply[A](x: (Option[A], Option[A])): Option[A] = x._1 orElse x._2 } (Note that I’ve named the function f instead of mapper to avoid confusion with the mapper implicit … Read more

Any reason why scala does not explicitly support dependent types?

Syntactic convenience aside, the combination of singleton types, path-dependent types and implicit values means that Scala has surprisingly good support for dependent typing, as I’ve tried to demonstrate in shapeless. Scala’s intrinsic support for dependent types is via path-dependent types. These allow a type to depend on a selector path through an object- (ie. value-) … Read more