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
12
votes
1 answer

Mapping over Shapeless record

In a Play application I'm working on, I'm trying to improve our system for processing flags, some of which are meant to be persistent options as a user navigates our app via links. I'd like to use Shapeless to map from a definition of the option to…
acjay
  • 34,571
  • 6
  • 57
  • 100
11
votes
2 answers

Update case class from incomplete JSON with Argonaut or Circe

I need to create an updated instance from a case class instance (with any needed DecodeJsons implicitly derived), given an incomplete json (some fields missing). How can this be accomplished with Argonaut (preferably) or Circe (if I have…
eirirlar
  • 814
  • 6
  • 24
11
votes
1 answer

Shapeless define lens for base trait

I have the next code trait A { val id: Int } case class B(id: Int) extends A case class C(id: Int, name: String) extends A i want to define common lens for all class hierarchy: import shapeless._ import lens._ val idLens = lens[A] >> 'id But i…
lito
  • 989
  • 8
  • 21
11
votes
1 answer

Scala Shapeless Code for Project Euler #1

I am new to shapeless and have been trying to practice some type level programming. I took Problem #1 from Project Euler as my first challenge. I started by writing regular scala code: object ProjectEuler1 { def e1(limit: Int) = (1 until…
beefyhalo
  • 1,691
  • 2
  • 21
  • 33
11
votes
3 answers

Shapeless: map from coproduct to different coproduct

In the following, I'm trying to make a polymorphic function to convert a RawFeatureValue into a RefinedFeatureValue. import shapeless._ object test { type RawFeatureValue = Int :+: Double :+: String :+: CNil type RefinedFeatureValue = Int :+:…
Utaal
  • 8,484
  • 4
  • 28
  • 37
11
votes
2 answers

How to shapeless case classes with attributes and typeclasses?

I am currently implementing a library to serialize and deserialize to and from XML-RPC messages. It's almost done but now I am trying to remove the boilerplate of my current asProduct method using Shapeless. My current code: trait Serializer[T] { …
Jorge
  • 784
  • 4
  • 17
11
votes
1 answer

How to require typesafe constant-size array in scala?

I need something like this: def encryptBlock(arr: FixedArray[Size16]) = ??? val blocks = originalArray.splitFixed[Size16] val encrypted = encryptBlock(blocks) In order to be sure that I receive only 128-bit array as input.
dk14
  • 22,206
  • 4
  • 51
  • 88
11
votes
1 answer

scala path dependent types and type level proofs

I am currently trying to define a model of a clocked dataflow language in scala. A flow virtually represents an infinite sequence of values of some type T, paced by some clock C (a clock indicates at which moments the flow is actually…
11
votes
2 answers

What is the purpose of the emptyCoproduct and coproduct methods of the TypeClass trait in Shapeless

It is not fully clear to me what is the purpose of the emptyCoProduct and coproduct methods of the TypeClass trait in Shapeless. When would one use the TypeClass trait instead of the ProductTypeClass? What are some examples of ways those two methods…
jedesah
  • 2,983
  • 2
  • 17
  • 29
11
votes
1 answer

Shapeless: generic lens parameterized by case class or field

Based on: import shapeless._ case class Content(field: Int) lens[Content] >> 'field I am trying to make a lens-creating method, something along: def makeLens[T <: Product](s: Symbol) = lens[T] >> s But it seems non-obvious. Is it possible to…
ponythewhite
  • 617
  • 3
  • 8
11
votes
1 answer

Issue resolving arity of function args to drive list processing, using Shapeless

The following gist has the code for an idea I am playing with package com.test1 import scala.language.implicitConversions import shapeless._ import FromTraversable._ import Traversables._ import Nat._ import Tuples._ trait ToArity[P, N <:…
dconlon
  • 113
  • 4
10
votes
1 answer

Scala type constraint to check argument values

I'm trying to implement Conway's surreal numbers in Scala. A surreal number is defined recursively – as a pair of sets of surreal numbers, called left and right, such that no element in the right set is less than or equal to any element in the left…
10
votes
1 answer

Decoding Shapeless Tagged Types

Given the following on Ammonite: @ import $ivy.`io.circe::circe-core:0.9.0` @ import $ivy.`io.circe::circe-generic:0.9.0` @ import $ivy.`com.chuusai::shapeless:2.3.3` @ import shapeless.tag import shapeless.tag @ trait Foo…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
10
votes
1 answer

Strange type error after "inlining" a val

I'm observing a very strange type error with shapeless.everywhere. Consider the following ammonite script which loads fine with load.module: load.ivy("com.chuusai" %% "shapeless" % "2.3.0") @ import shapeless._ import poly._ final case class…
user355252
10
votes
0 answers

Adding Container types like Seq, List, Option, and Map to shapeless generic conversion

In order to complete the series of questions that I've asked about conversion of case class to/from Map[String, Any] in 1 and 2, I wanted to know how can one extend those answers mentioned above to work with container types,…
Omid
  • 1,959
  • 25
  • 42