shapeless

Map for generic HList

*爱你&永不变心* 提交于 2019-12-12 03:06:45
问题 Say we have following method def func[T <: HList](hlist: T, poly: Poly) (implicit mapper : Mapper[poly.type, T]): Unit = { hlist map poly } and custom Poly object f extends (Set ~>> String) { def apply[T](s : Set[T]) = s.head.toString } So I can use this func like func(Set(1, 2) :: Set(3, 4) :: HNil, f) In my code I have small number of Polies and a big number of func invocations. For this purpose I tried to move poly: Poly to implicit parameters and got expected message illegal dependent

Defining instances of a third-party typeclass, implicit not found but explicit works fine

◇◆丶佛笑我妖孽 提交于 2019-12-11 17:24:35
问题 I'm working with Slick's GetResult typeclass and wanted to use Shapeless to derive instances of GetResult[Option[(A, B, C...)]] What I want: Given an implicit GetResult[Option[A]], GetResult[Option[B]], ... , implicitly generate a GetResult[Option[(A, B, ...)]] What I tried trait CanGetOption[T] { def getOption: GetResult[Option[T]] } object CanGetOption { // convenience implicit resolver def apply[T](implicit canGetOption: CanGetOption[T]): CanGetOption[T] = canGetOption // base case: HNil

Kittens - ambiguous imports

人盡茶涼 提交于 2019-12-11 12:07:42
问题 I have taken the following code almost entirely from the 'derive show' example found here: https://github.com/milessabin/kittens import cats._, cats.derived._, cats.implicits._ object Test extends App { case class Address(street: String, city: String, state: String) case class ContactInfo(phoneNumber: String, address: Address) case class People(name: String, age: Double, contactInfo: ContactInfo) val mike = People("Mike", 1.23, ContactInfo("202-295-3928", Address("1 Main ST", "Chicago", "IL")

Is there a way to guarantee case class copy methods exist with type classes in Scala?

心已入冬 提交于 2019-12-11 07:58:13
问题 In the example below I have a type class Foo , and would like to somehow guarantee that all members conforming to Foo (such as Bar via barFoo ) have a copy method such as the one generated by way of being a case class . I haven't thought of a way to do this. In this case the copy signature would be possibly be something like copy(foo: F, aa: List[T] = foo.aa, maybe: Option[T] = foo.maybe): F . trait Foo[F] { type T def aa(foo: F): List[T] def maybe(foo: F): Option[T] } final case class Bar(aa

Building Fixed Size List of Nat N

倖福魔咒の 提交于 2019-12-11 06:24:26
问题 I tried to define a function that, given a N <: Nat type parameter, builds a List with exactly 3 N 's. import shapeless._ import shapeless.nat._ scala> def natNOfSize3[N <: Nat](n: Nat): Sized[List[N], _3] = Sized[List, _3](List(n, n, n)) <console>:17: error: wrong number of type parameters for overloaded method value apply with alternatives: [CC[_]]()(implicit cbf: scala.collection.generic.CanBuildFrom[Nothing,Nothing,CC[Nothing]], implicit ev: shapeless.AdditiveCollection[CC[Nothing]]

Out of memory error during Scala compilation

孤者浪人 提交于 2019-12-11 05:59:20
问题 I'm using the macro-heavy scala-pickling along with shapeless , and I keep crashing the Scala 2.10.3 compiler with an apparent out of memory error. The tail of the error message looks like this: [error] <tpt> // tree.tpe=tasks.anonfun$218 [error] Block( // tree.tpe=Unit [error] Apply( // def <init>(): scala.runtime.AbstractFunction1 in class AbstractFunction1, tree.tpe=scala.runtime.AbstractFunction1 [error] SimpleMiddlebury$$anonfun$218.super."<init>" // def <init>(): scala.runtime

Shapeless LabelledGeneric but ignoring some fields

牧云@^-^@ 提交于 2019-12-11 04:42:20
问题 I would like to define a shapeless LabelledGeneric that ignores one (or more) fields when converting to HList ; when converting the HList back again it should substitute a user-defined value. The goal is to be able to write something like this: case class Foo(i: Int, s: String) val foo = Foo(123, "Hello") val gen = LabelledGeneric[Foo].ignoring('i)(defaultValue = -1) val hlist = gen.to(foo) // "Hello" :: HNil val foo2 = gen.from(hlist) assert(foo2 == Foo(-1, "Hello")) This is what I have so

Mapping over HList raises AbstractMethodError

旧时模样 提交于 2019-12-11 04:38:26
问题 I am trying a shapeless example in REPL and getting a runtime error: scala> import shapeless._ import shapeless._ scala> import shapeless.poly._ import shapeless.poly._ scala> object choose extends (Set ~> Option) { | def apply[T](set: Set[T]) = set.headOption | } defined object choose scala> val sets = Set(1) :: Set(0) :: HNil sets: shapeless.::[scala.collection.immutable.Set[Int],shapeless.::[scala.collection.immutable.Set[Int],shapeless.HNil]] = Set(1) :: Set(0) :: HNil scala> sets map

Get case class field's name and type with shapeless

跟風遠走 提交于 2019-12-11 04:10:00
问题 Is it possible to get scala case class field's names and types with shapeless? I've tried like this (T is case class): trait Cpo[T] { def withPrimaryKey[R <: HList, K, V <: HList](f: Seq[Symbol] => Seq[Symbol])( implicit labellGeneric: LabelledGeneric.Aux[T, R], keys: Keys.Aux[R, K], ktl: hlist.ToList[K, Symbol]): Cpo[T] } but I only can get field's name. Zlaja 回答1: Try object typeablePoly extends Poly1 { implicit def default[A](implicit typeable: Typeable[A]): Case.Aux[A, String] = at(_ =>

Shapeless and gremlin scala: How do I return the result of a call to `as`?

☆樱花仙子☆ 提交于 2019-12-11 04:09:56
问题 So, I am calling this function as (from gremlin-scala ): case class GremlinScala[End, Labels <: HList](traversal: GraphTraversal[_, End]) { def as(name: String, moreNames: String*)(implicit p: Prepend[Labels, End :: HNil]) = GremlinScala[End, p.Out](traversal.as(name, moreNames: _*)) } It is defined here: https://github.com/mpollmeier/gremlin-scala/blob/master/gremlin-scala/src/main/scala/gremlin/scala/GremlinScala.scala#L239 It takes an implicit Prepend argument, which I am not sure I