shapeless

Scala shapeless Generic.Aux implicit parameter not found in unapply

旧城冷巷雨未停 提交于 2020-01-05 06:26:46
问题 I encountered the following problem with implicits in Scala, using Shapeless's Generic.Aux : case class Complex(re: Double, im: Double) object Prod2 { def unapply[C, A, B](c: C)(implicit C: Generic.Aux[C, A :: B :: HNil]) = Some((C.to(c).head, C.to(c).tail.head)) } val c = Complex(1.0, 2.0) val Prod2(re, im) = c The code above does not compile. It reports Error:(22, 7) could not find implicit value for parameter C: shapeless.Generic.Aux[nexus.ops.Test.Complex,A :: B :: shapeless.HNil] val

Achieving compile safe indexing with Shapeless

痞子三分冷 提交于 2020-01-05 04:26:07
问题 Problem: Let val v = List(0.5, 1.2, 0.3) model a realisation of some vector v = (v_1, v_2, v_3). The index j in v_j is implied by the element's position in the list. A lot of boilerplate and bugs have been due to tracking these indices, eg, when creating modified lists from the original. (How to make sure (in compile-time) that collection wasn't reordered? seems related.) General question: What could be a good way to ensure correct indexing at compile time? (I assume that performance is not

Shapeless: restricting case class types

心已入冬 提交于 2020-01-05 01:37:14
问题 (NOTE: split from Shapeless: Trying to restrict HList elements by their type and Shapeless: own HList constraint using Coproduct ) Question 3 - restrict case classes by parameter types A very nice additional gain would be, if I could use HList constraints to constrain case class only to be built from AnyVals, Strings, and a specific MyBaseTrait, that recursively fulfill the same constraint. The constraint being defined on the base trait and not to have to touch any derived case class would be

Shapeless: restricting case class types

孤街醉人 提交于 2020-01-05 01:36:07
问题 (NOTE: split from Shapeless: Trying to restrict HList elements by their type and Shapeless: own HList constraint using Coproduct ) Question 3 - restrict case classes by parameter types A very nice additional gain would be, if I could use HList constraints to constrain case class only to be built from AnyVals, Strings, and a specific MyBaseTrait, that recursively fulfill the same constraint. The constraint being defined on the base trait and not to have to touch any derived case class would be

Getting elements from Slick HLIST (or Convert Slick HLIst into Shapeless HList)

筅森魡賤 提交于 2020-01-02 13:17:32
问题 I have auto-generated scala code using slick codegen. I see that some tables Rows are implements as HLists. (but these are slick HList, not the normal shapeless HList) Now I want a specific element from the HList returned as a Row by the slick query. I googled and found this thread Getting elements from an HList But this does not work for slick HList. it works very well for Shapeless HList I also tried the apply method val x : Long = slickHList(2) but this doesn't compile because type Any

Checking for subtype relationship between extensible records in shapeless

自闭症网瘾萝莉.ら 提交于 2020-01-02 07:32:09
问题 I have two shapeless extensible records, person and employee . The employee record is a subtype of person in some sense because it has all of the fields that person does and those fields are all subtypes of the corresponding fields in person : import shapeless._ ; import syntax.singleton._ ; import record._ val employeeId = ("first name" ->> "Jane") :: ("last name" ->> "Doe") :: ("title" ->> "software engineer") :: HNil val employee = ("id" ->> employeeId) :: ("city" ->> "San Francisco") :: (

Checking for subtype relationship between extensible records in shapeless

六月ゝ 毕业季﹏ 提交于 2020-01-02 07:32:05
问题 I have two shapeless extensible records, person and employee . The employee record is a subtype of person in some sense because it has all of the fields that person does and those fields are all subtypes of the corresponding fields in person : import shapeless._ ; import syntax.singleton._ ; import record._ val employeeId = ("first name" ->> "Jane") :: ("last name" ->> "Doe") :: ("title" ->> "software engineer") :: HNil val employee = ("id" ->> employeeId) :: ("city" ->> "San Francisco") :: (

LabelledGeneric to get class name

我的梦境 提交于 2020-01-01 05:59:50
问题 I'm fairly new to Shapeless, as one will infer from my question. Given an instance of LabelledGeneric , how do I get the name of the class that it represents. I can get the field name information from Keys , so I assume I need some other kind of Witness that encapsulates the type itself, but I cannot figure out which. Eg, if I have a case class called Foo in package com.bar, I want to get the string "com.bar.Foo" (or separately is fine). implicit def example[T, Repr <: HList](implicit label:

In shapeless, have two lists such that one contains typeclasses of the other

烈酒焚心 提交于 2020-01-01 04:56:07
问题 In shapeless I'm trying to write a function such that takes two HLists l1 and l2 of arbitrary length which exhibit the following properties: Length of l1 and l2 are the same. l2 contains the exact types of l1 , wrapped in a constant outer type constructor. So, if l1 was 1 :: 1.2 :: "hello" :: HNil` l2 could be Ordering[Int] :: Ordering[Double] :: Ordering[String] :: HNil Using UnaryTCConstraint and LengthAux lets me constrain the lengths and require a static outer constructor for l2 , however

shapeless HList to TupleN where the tuple shape need not exactly match the HList shape

限于喜欢 提交于 2020-01-01 04:32:07
问题 I would like to create the equivalent of: def toTupleN[A1, ..., AN, L <: HList](l: L): TupleN[A1, ..., AN] Code using toTupleN should compile only when there is exactly one N combination of values in l that the tuple could be created from. Anything else should generate a compile-time error. Available implicit conversions should be taken into account. Note that there are no restrictions on the size of l or the ordering of values in it. Example: val l = 23 :: (1, "wibble") :: (2, "wobble") ::