hlist

HList to nested Map

半世苍凉 提交于 2019-12-08 02:42:28
I would like to transform an HList type parameter to a nested Map-type, e.g. Int :: String :: String :: HNil should become Map[Int, Map[String, Map[String, T]]]] where T would be another type parameter of the same function, like: def somedef[T, L <: HList](t: T)(implicit f: ???): f.Out where f.Out is T in case of HNil or a nested Map-structure with dept L.size Is there any way this can be done? I'm not aware of a standard thing to do such a transformation, but you could roll out your custom converter in the same way as various HList ops (like map ) are implemented inside shapeless (see trait

Invoke a Scala Function2 with a shapeless HList whose values do not match the argument order

倖福魔咒の 提交于 2019-12-07 17:47:43
问题 I'd like to build the equivalent of: def applyWithHList2[A1, A2, R, L <: HList](l: L, f: Function2[A1, A2, R]): Try[R] The values in the list are such that in the N choose 2 possible value combinations of l.unify there is at most one that could be used to call the function. No additional type information is available. If there is no way to call the function, the result should be Failure with MatchError . Otherwise, the result should be Try(f(a1, a2)) . I am still getting used to shapeless and

Generic Poly2 Folder case for shapeless Hlist

こ雲淡風輕ζ 提交于 2019-12-07 05:29:51
问题 I am trying to transform the following HList Some(C(15)) :: None :: Some(B(55)) :: None :: Some(A(195)) :: HNil to C(15) :: B(55) :: A(195) :: HNil Here is what I have at the moment : import shapeless._ case class A(value: Int) case class B(value: Int) case class C(value: Int) trait folderLP extends Poly2 { implicit def default[T, L <: HList] = at[T, L]((acc, t) => acc) } object folder extends folderLP { implicit def none[T, L <: HList] = at[None.type, L]((t, acc) => acc) implicit def

Why does mapping over an HList of Option[T] not work?

三世轮回 提交于 2019-12-07 01:56:27
问题 This does not compile and I do not understand why: import shapeless._ import poly._ object option extends (Option ~> List) { def apply[T](t: Option[T]) = t.toList } val simple = Some(1) :: Some("hello") :: Some(true) :: HNil val opts: List[Int] :: List[String] :: List[Boolean] :: HNil = simple map option This is somewhat surprising, because this does compile: import shapeless._ import poly._ object choose extends (Set ~> Option) { def apply[T](s: Set[T]) = s.headOption } val sets = Set(1) ::

HList filtered by foldRight is not providing instances

徘徊边缘 提交于 2019-12-06 09:31:56
问题 I'm using libraryDependencies += "com.chuusai" %% "shapeless" % "2.2.4" Currently i have model HList types like sealed trait Section case class Header(...) extends Section case class Customer(...) extends Section case class Supplier(...) extends Section case class Tech(...) extends Section type ContractView = Header :: (Customer :: Supplier :: HNil) :: Tech :: HNil In my user code, i'd like to filter technical sections that are not supposed to view using foldRight as proposed in this answer:

Generic Poly2 Folder case for shapeless Hlist

[亡魂溺海] 提交于 2019-12-05 10:20:22
I am trying to transform the following HList Some(C(15)) :: None :: Some(B(55)) :: None :: Some(A(195)) :: HNil to C(15) :: B(55) :: A(195) :: HNil Here is what I have at the moment : import shapeless._ case class A(value: Int) case class B(value: Int) case class C(value: Int) trait folderLP extends Poly2 { implicit def default[T, L <: HList] = at[T, L]((acc, t) => acc) } object folder extends folderLP { implicit def none[T, L <: HList] = at[None.type, L]((t, acc) => acc) implicit def someDiameter[T, L <: HList] = at[Some[C], L]((t, acc) => t.get :: acc) implicit def someRatio[T, L <: HList] =

Why does mapping over an HList of Option[T] not work?

依然范特西╮ 提交于 2019-12-05 08:31:04
This does not compile and I do not understand why: import shapeless._ import poly._ object option extends (Option ~> List) { def apply[T](t: Option[T]) = t.toList } val simple = Some(1) :: Some("hello") :: Some(true) :: HNil val opts: List[Int] :: List[String] :: List[Boolean] :: HNil = simple map option This is somewhat surprising, because this does compile: import shapeless._ import poly._ object choose extends (Set ~> Option) { def apply[T](s: Set[T]) = s.headOption } val sets = Set(1) :: Set("foo") :: HNil val opts: Option[Int] :: Option[String] :: HNil = sets map choose The problem is

Map on HList in method with Poly1 based on type parameter of class

て烟熏妆下的殇ゞ 提交于 2019-12-05 01:38:11
问题 I have class, parameterized with HList and some other type. How can I use map on HList in one of its methods? Compilation of this code throws java.lang.AssertionError : class Test[L <: HList, P](l: L, p: P) { type Cont[T] = (P, T) object generator extends (Id ~> Cont) { def apply[T](t: T) = p -> t } def test(implicit m: Mapper[generator.type, L]) = { l map generator } } new Test(1 :: HNil, 'a).test // java.lang.AssertionError My goal is this kind of result: type Cont[T] = (Symbol, T) val p =

HList filtered by foldRight is not providing instances

核能气质少年 提交于 2019-12-04 14:54:59
I'm using libraryDependencies += "com.chuusai" %% "shapeless" % "2.2.4" Currently i have model HList types like sealed trait Section case class Header(...) extends Section case class Customer(...) extends Section case class Supplier(...) extends Section case class Tech(...) extends Section type ContractView = Header :: (Customer :: Supplier :: HNil) :: Tech :: HNil In my user code, i'd like to filter technical sections that are not supposed to view using foldRight as proposed in this answer : trait collectAllRF extends Poly2 { implicit def atAny[L <: HList, X] = at[X, L](_ :: _) } object

Find type class instances for Shapeless HList

笑着哭i 提交于 2019-12-04 11:17:14
问题 Say that I have a trait Show[T] such as the one in Scalaz: https://github.com/scalaz/scalaz/blob/scalaz-seven/core/src/main/scala/scalaz/Show.scala#L9 I also have a Shapeless HList that may look like "1" :: 2 :: 3L :: HNil . Is there a way to find the Show instance for each element and apply shows such that I end up with "1" :: "2" :: "3L" :: HNil ? If any element were of a type that did not have an implicit Show instance in scope I would want a compile error. I think that if I build up an