shapeless

Is there infrastructure in shapeless that takes a type constructor to the power of a Nat?

别说谁变了你拦得住时间么 提交于 2019-12-06 11:28:50
To me this appears as a very basic functionality, but I can't find it in current shapeless (2.3.3). So I am looking for a type Induction[X,F[_],N <: Nat] with Induction[X,F,Nat._0].Out =:= X Induction[X,F,Nat._1].Out =:= F[X] Induction[X,F,Nat._2].Out =:= F[F[X]] ... Maybe it's also possible to chain a function along the type construction, e.g., to construct a Point instance? No there isn't. As you observe this most likely needs a Point -like type class to be useful. I suggest adding something like this to Kittens which depends on both shapeless and Cats. 来源: https://stackoverflow.com

Test two scala shapeless HList types for equivalence via implicit

半腔热情 提交于 2019-12-06 10:21:19
I'm interested in testing whether two HList heterogeneous records are "equivalent"; that is, they have the same key/val pairs, but not necessarily in the same order. Is there a predefined type predicate that does what EquivHLists does in the code fragment below? // shapeless heterogeneous records with "equivalent" types. // these should compile if given as the arguments to 'f' below. val hrec1 = ("a" ->> 1) :: ("b" ->> 2) :: HNil val hrec2 = ("b" ->> 2) :: ("a" ->> 1) :: HNil // only compiles if two HList records contain same information def f(hr1: H1 <: HList, hr2 : H2 <: HList)(implicit

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:

Deriving HList of zeroes from a type of HList of Monoids

一笑奈何 提交于 2019-12-06 08:05:07
问题 I am learning shapeless, and currently I am trying to create a function that does the following: given a type of an HList it returns the HList of None s, with the Option types corresponding to given HList type. For instance: create[String :: Int :: HNil] // returns None[String] :: None[Int] :: HNil So the logic is the following: def create[A <: HList] { type HT = ??? //somehow getting Head type type TT = ??? //somehow getting Tail type // if HT is HNil HNil else Option.empty[HT] :: create[TT]

Type-level Shapeless : aggregating a HList type elements

好久不见. 提交于 2019-12-06 08:03:01
问题 I want to fold a HList with this Monad but at the type-level trait TypeMonad{ type Append[A,B] = A with B type Identity = Any } Hence, the HList : "A :: B:: C :: HNil " would give the type " A with B with C with Any" Quite easy to do if i had implemented HList : sealed trait HList { type Fuse } final trait HCons[H,L<:HList] extends HList { type Fuse = H with L#Fuse } final trait HNil extends Hlist { type Fuse = Any } However I don't know how to have this functionality in the shapeless

Idiomatic Scala way of deserializing delimited strings into case classes

浪尽此生 提交于 2019-12-06 07:19:47
问题 Suppose I was dealing with a simple colon-delimited text protocol that looked something like: Event:005003:information:2013 12 06 12 37 55:n3.swmml20861:1:Full client swmml20861 registered [entry=280 PID=20864 queue=0x4ca9001b] RSET:m3node:AUTRS:1-1-24:A:0:LOADSHARE:INHIBITED:0 M3UA_IP_LINK:m3node:AUT001LKSET1:AUT001LK1:r OPC:m3node:1-10-2(P):A7:NAT0 .... I'd like to deserialize each line as an instance of a case class, but in a type-safe way. My first attempt uses type classes to define

Scala shapeless KList with extra constraint

帅比萌擦擦* 提交于 2019-12-06 07:01:43
问题 I want to take this pattern: def accept[T](a: RList[T]) = true def accept[T, V](a: RList[T], b: RList[V])(implicit ev: a.S =:= b.S) = true def accept[T, V, Q](a: RList[T], b: RList[V], c: RList[Q])(implicit ev: a.S =:= b.S, ev2: b.S =:= c.S) = true but have it accept a KList , instead of manually overriding for all arities. Basically I want to say, "Take any number of RList s, that have the same S member type" RList is a trait, that contains a type S . (For more background on an RList and why

Shapeless deconstruct tuple in type parameter declaration

眉间皱痕 提交于 2019-12-06 06:23:52
问题 I am using a RightFolder that returns a Tuple2 and would like to return the _1 part. The first version rightFoldUntupled1 works fine but uses an additional IsComposite typeclass. In the second version rightFoldUntupled2 I try to achieve the same without IsComposite by destructuring P as a Product2[_, Values] . That doesn't work any more - the compiler is happy to witness that P is a Product2[_,_] , but as soon as I use a named type parameter for _1 it doesn't compile any more. Any idea why?

toList on shapeless HList fails when resulting existential type too complex

孤者浪人 提交于 2019-12-06 04:32:26
问题 Given the following definitions: class R[T] class A class B class C This works: val s1 = new R[A] :: new R[B] :: HNil val r1 = s1.toList // r1 of type: List[R[_ >: A with B]] While this does not: val s2 = new R[A] :: new R[B] :: new R[C] :: HNil val r2 = s2.toList // could not find implicit value for parameter toList: // shapeless.ToList[shapeless.::[R[A], // shapeless.::[R[B],shapeless.::[R[C],shapeless.HNil]]],Lub] Where I expect: // r2 of type: List[R[_ >: A with B with C]] Pseudo solution

Diverging implicit expansion for type class

半世苍凉 提交于 2019-12-06 03:50:32
I'm trying to extend the Parser type class from this blog post to support nested case classes parsing. Since I'm new to shapeless, I've decided to start with the non-general case, that would only support a case class with 2 fields that are themselves case classes. To illustrate this better, here's the case classes definition first: case class Person(name: String, age: Int) case class Family(husband: Person, wife: Person) In addition to the code from that blog post, I've created one more implicit function that is supposed to support my case, parsing Family class from the string like "Hans,70