Questions tagged [shapeless]

shapeless is (an exploration of) a type class and dependent type based generic (aka polytypic/polymorphic) programming library for Scala.

shapeless is (an exploration of) a type class and dependent type based generic (aka polytypic/polymorphic) programming library for Scala derived from the various talks Miles Sabin has given over the course of 2011 on implementing scrap your boilerplate and higher rank polymorphism in Scala.

shapeless is an Open Source project under the Apache License v2.

1030 questions
24
votes
1 answer

Shapeless: Generic.Aux

I'm trying to understand how Generic works (and TypeClass too). The github wiki is very sparse on examples and documentation. Is there a canonical blog post / documentation page describing Generic and TypeClass in detail? In concrete, what is the…
Juanpa
  • 667
  • 6
  • 8
24
votes
2 answers

Shapeless - turn a case class into another with fields in different order

I'm thinking of doing something similar to Safely copying fields between case classes of different types but with reordered fields, i.e. case class A(foo: Int, bar: Int) case class B(bar: Int, foo: Int) And I'd like to have something to turn a A(3,…
Utaal
  • 8,484
  • 4
  • 28
  • 37
24
votes
1 answer

how do i start learning shapeless concepts in scala

I would like to learn about polytypic concepts in Scala, I came across shapeless library what would be the best starting point for learning and applying shapeless.
prassee
  • 3,651
  • 6
  • 30
  • 49
22
votes
2 answers

Weird behavior trying to convert case classes to heterogeneous lists recursively with Shapeless

I stayed up way too late last night trying to figure out this Shapeless issue and I'm afraid it's going to eat my evening if I don't get it off my chest, so here goes. In this minimized version I'm just defining a type class that will recursively…
Travis Brown
  • 138,631
  • 12
  • 375
  • 680
21
votes
1 answer

Getting subclasses of a sealed trait

Is it possible (via macros, some form of Shapeless automagic or otherwise) to obtain a list of the subclasses of a sealed trait: At compile time? At runtime?
NietzscheanAI
  • 966
  • 6
  • 16
20
votes
1 answer

Converting Map[String,Any] to a case class using Shapeless

The question here asks about mapping a case class to a Map[String,Any]. I was wondering what would be the other way around, converting Map[String,Any] to a case class. Given the following map: val mp = Map("name" -> "Tom", "address" -> Map("street"…
Omid
  • 1,959
  • 25
  • 42
19
votes
2 answers

How to define a function whose output type depends on the input type

Given the following classes: case class AddRequest(x: Int, y: Int) case class AddResponse(sum: Int) case class ToUppercaseRequest(str: String) case class ToUppercaseResponse(upper: String) How do I define in a typesafe manner some function: def…
jvliwanag
  • 1,508
  • 1
  • 13
  • 29
19
votes
2 answers

Converting nested case classes to nested Maps using Shapeless

I am trying to solve [this][1] question using Shapeless, in summary it's about converting a nested case class to Map[String,Any], here is the example: case class Person(name:String, address:Address) case class Address(street:String, zip:Int) val p…
Omid
  • 1,959
  • 25
  • 42
19
votes
1 answer

Extract label values from a LabelledGeneric instance

Consider the following example: import shapeless._ case class Foo(bar: String, baz: Boolean) val labl = LabelledGeneric[Foo] Now, the type of labl is (prettified) LabelledGeneric[Foo] { type Repr = FieldType[Symbol @@ String("bar"), String]…
Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
19
votes
5 answers

Converting a tuple of options to an option of tuple with Scalaz or Shapeless

Having (Some(1), Some(2)) I expect to get Some((1, 2)) and having (Some(1), None) I expect to get None
Nikita Volkov
  • 42,792
  • 11
  • 94
  • 169
18
votes
2 answers

Understanding the Aux pattern in Scala Type System

This question may be asked and answered before, but I would like to understand this with an example and I could not reason out where the Aux pattern might be helpful! So here is the trait: trait Foo[A] { type B def value: B } Why do I have a…
joesan
  • 13,963
  • 27
  • 95
  • 232
18
votes
2 answers

Passing a Shapeless Extensible Record to a Function

I am trying to learn Shapeless (using version 2.10.2). I have created a very simple extensible record: val rec1 = ("foo" ->> 42) :: HNil According to the REPL, this has type shapeless.::[Int with…
Eduardo
  • 8,362
  • 6
  • 38
  • 72
18
votes
7 answers

Different types in Map Scala

I need a Map where I put different types of values (Double, String, Int,...) in it, key can be String. Is there a way to do this, so that I get the correct type with map.apply(k) like val map: Map[String, SomeType] = Map() val d: Double =…
pichsenmeister
  • 2,132
  • 4
  • 18
  • 34
18
votes
2 answers

Sequencing an HList

Given a Shapeless HList where every list element shares the same type constructor, how can the HList be sequenced? For example: def some[A](a: A): Option[A] = Some(a) def none[A]: Option[A] = None val x = some(1) :: some("test") :: some(true) ::…
mpilquist
  • 3,855
  • 21
  • 22
17
votes
1 answer

What are the important features of the shapeless API (in Scala), and what do they do?

I'm trying to learn shapeless (2.0.0). It seems like an amazing tool and I'm very excited about it, but I am having problems moving forward. Because there is not yet much documentation, I've been poring over examples and the source code. I am…
jcrudy
  • 3,921
  • 1
  • 24
  • 31
1
2
3
68 69