shapeless

Slick 2.10-RC1, Scala 2.11.x, bypassing 22 arity limit with case class (heterogenous)

故事扮演 提交于 2019-12-04 12:18:26
问题 I am having issues in mapping a Table that has > 22 columns specifically into a case class , assuming you have the following code import slick.driver.PostgresDriver import scala.slick.collection.heterogenous._ import syntax._ import shapeless.Generic case class TwentyThreeCaseClass( val id:Option[Long], val one:String, val two:String, val three:String, val four:String, val five:String, val six:String, val seven:String, val eight:String, val nine:String, val ten:String, val eleven:String, val

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

toList on shapeless HList fails when resulting existential type too complex

不打扰是莪最后的温柔 提交于 2019-12-04 10:59:57
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: Supply implicit yourself: val r3 = s2.toList(ToList.hlistToList[R[A], R[B], ::[R[C], HNil], R[_ >: A

Scala Function.tupled and Function.untupled equivalent for variable arity, or, calling variable arity function with tuple

会有一股神秘感。 提交于 2019-12-04 08:26:50
问题 I was trying to do some stuff last night around accepting and calling a generic function (i.e. the type is known at the call site, but potentially varies across call sites, so the definition should be generic across arities). For example, suppose I have a function f: (A, B, C, ...) => Z . (There are actually many such f s, which I do not know in advance, and so I cannot fix the types nor count of A, B, C, ..., Z .) I'm trying to achieve the following. How do I call f generically with an

Can Map be performed on a Scala HList

谁说我不能喝 提交于 2019-12-04 07:44:24
问题 I have done a few implementations of HList now. One based on Daniel Spiewak's High Wizardry in the Land of Scala talk and another based on a post in Apocalisp blog. The goal was to have a heterogenous list of which is not heterogenous in the primary type but rather the higher kind. For example: val requests = Request[String] :: Request[Int] :: HNil I would be able to do a map across the list to perform the request and result in a heterogenous list of the higher kind. So: requests.map(execute)

Understanding `Monomorphism` Example of Shapeless

心已入冬 提交于 2019-12-04 05:46:52
The Shapeless Features Overview shows the following example: import poly._ // choose is a function from Sets to Options with no type specific cases object choose extends (Set ~> Option) { def apply[T](s : Set[T]) = s.headOption } scala> choose(Set(1, 2, 3)) res0: Option[Int] = Some(1) scala> choose(Set('a', 'b', 'c')) res1: Option[Char] = Some(a) However, I don't, in m lack of experience with Shapeless, understand the difference between that and the following: scala> def f[T](set: Set[T]): Option[T] = set.headOption f: [T](set: Set[T])Option[T] scala> f( Set(1,2,3) ) res0: Option[Int] = Some(1

Using shapeless scala to merge the fields of two different case classes

你离开我真会死。 提交于 2019-12-04 04:18:53
I want to merge the fields of two different case classes into a single case class. For example, if I have the following case classes: case class Test(name:String, questions:List[Question], date:DateTime) case class Answer(answers:List[Answers]) I want a concise shapeless way to merge both into: TestWithAnswers(name:String, questions:List[Question], date:DateTime, answers:List[Answer]). Is there a nice shapeless answer out there? You can use shapeless Generic to do this. val t: Test = ??? val a: Answer = ??? val gt = Generic[Test] val ga = Generic[Answer] val gta = Generic[TestWithAnswers] val

Map on HList fails with subtypes of generic type in Scala & Shapeless

元气小坏坏 提交于 2019-12-04 03:31:00
Say we have the following classes and some values (in Scala): class A[T](val x: T) class B[T](x: T, val y: T) extends A[T](x) val x1 = new A("test") val x2 = new B(1,2) val x3 = new B("foo","bar") val x4 = new A(1) Further, we define the following polymorphic function value (using shapeless): object f extends (A ~> Option) { def apply[T](s: A[T]) = Some(s.x) } Now we can call: f(x1); f(x2); f(x3); f(x4) Which all succeed (and should IMHO). However: val list = x1 :: x2 :: x3 :: x4 :: HNil list.map(f) // could not find implicit value for parameter mapper: // shapeless.Mapper[f.type,shapeless.::

How to iterate all the product types in a coproduct using shapeless?

邮差的信 提交于 2019-12-03 17:31:35
问题 Let's say I have a coproduct (a sealed trait) such as sealed trait Traity case object Foo extends Traity case class Bar() extends Traity case class Baz() extends Traity Using shapeless, I can apply polymorphic functions to specific instances but what I'd like to do is to apply a zero-parameter (no-instance) polymorphic function to all the products (i.e. case classes and case objects). I have no idea what the syntax would look like, but something conceptually like: object mypoly extends Poly1

LabelledGeneric to get class name

与世无争的帅哥 提交于 2019-12-03 16:55:48
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: LabelledGeneric.Aux[T, Repr], kk: Keys[Repr]): Bibble[T] = new Bibble[T] { override def typeName(value: