Questions tagged [shapeless]

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

shapeless
Filter by
Sorted by
Tagged with
7 votes
4 answers
7k views

Scala parameters pattern (Spray routing example)

Sorry about the vague title...wasn't sure how to characterize this. I've seen/used a certain code construction in Scala for some time but I don't know how it works. It looks like this (example from ...
Greg's user avatar
  • 11k
13 votes
2 answers
4k views

Type casting using type parameter

Given is a Java method that returns java.lang.Objects for a given string. I'd like to wrap this method in a Scala method that converts the returned instances to some type T. If the conversion fails, ...
Fynn's user avatar
  • 4,823
2 votes
2 answers
190 views

How to return multiple variants of HList from a function?

Having class A class B extends A class C extends A class Container[+L <: HList](l: L) what is shapeless way to code as follows?: def foo[L <: HList](a: A): Container[L] = a match { case (b: ...
Alexander Myltsev's user avatar
2 votes
1 answer
368 views

How can I match case with shapeless variable?

How can I match case with shapeless variable ? Let's say I have variable of following type shapeless.::[String,shapeless.::[String,shapeless.HNil]] Currently I have to do this authHeaders.hrequire(...
expert's user avatar
  • 29.7k
18 votes
7 answers
15k views

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[...
pichsenmeister's user avatar
7 votes
1 answer
845 views

Shapeless: Checking Type Constraints of Polymorphic functions

I'm working on a small library for economic models that check the Units of the entities, using Types, e.g. instead of val apples = 2.0 we write val apples = GoodsAmount[KG, Apples](2.0). For creating ...
Klinke's user avatar
  • 207
24 votes
1 answer
6k views

how do i start learning shapeless concepts in scala [closed]

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's user avatar
  • 3,641
2 votes
1 answer
579 views

Pattern behind shapeless Aux classes

While studying shapeless and spray libraries, i've seen many inner Aux types, traits, objects and classes. It's not hard to understand that it is used for augmenting existing internal API, it looks ...
user avatar
2 votes
1 answer
242 views

Providing additional arguments to map on HList

I would like to do something like this: def run(subjects: List[Subject]) = { val configs = compute() subjects.map(s => configs.map(c => test(s,c))) // or flatMap, I don't really care at ...
gzm0's user avatar
  • 14.8k
4 votes
2 answers
574 views

toList on shapeless HList fails when resulting existential type too complex

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 ...
gzm0's user avatar
  • 14.8k
9 votes
1 answer
1k views

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

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") ...
gzm0's user avatar
  • 14.8k
14 votes
2 answers
909 views

How to represent a partial update on case classe in Scala ?

I have the following case class : case class PropositionContent(title:String,content:String) And I would like to represent a partial modification of it as Data. One way would be to create the ...
jwinandy's user avatar
  • 1,749
2 votes
1 answer
166 views

FP or typelevel tools to groupBy on deep leaf in nested data?

I got a deeply nested datastructure: Seq[Seq[(String, Seq[(String, Seq[(String, Try[Boolean])])], Long)]] Is there a nice functional way to groupBy on Try.isFailure? With Shapeless it is possible ...
ib84's user avatar
  • 675
18 votes
2 answers
2k views

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 ...
mpilquist's user avatar
  • 3,855
30 votes
4 answers
21k views

How to append or prepend an element to a tuple in Scala

I have a tuple and want to add an element without loosing type safety. This is what I want to achieve: val tuple = ("", 1, 1f) // (String, Int, Float) val newTuple:(String, Int, Float, Double) = ...
EECOLOR's user avatar
  • 11.2k
49 votes
5 answers
4k views

Testing an assertion that something must not compile

The problem When I'm working with libraries that support type-level programming, I often find myself writing comments like the following (from an example presented by Paul Snively at Strange Loop ...
Travis Brown's user avatar
14 votes
1 answer
1k views

Creating an HList of all pairs from two HLists

I'm using shapeless in Scala, and I'd like to write a function allPairs that will take two HLists and return an HList of all pairs of elements. For example: import shapeless._ val list1 = 1 :: "one" :...
emchristiansen's user avatar
6 votes
1 answer
394 views

How to splitAt a scala list using shapeless

I'm trying to split a list of size S at N, where it is known that N, M sum up to S. This does not compile: def splitIt[N <: Nat, M <: Nat, S <: Nat](u: Sized[List[Int]...
Peteris's user avatar
  • 3,656
2 votes
1 answer
263 views

How to implement [x] -> x in scala using shapeless?

def unreturn(lx: Sized[List[Int], Nat._1]): Int = lx head How to get the head of a list of one element using shapeless? This doesn't compile: No implicit view available from List[Int] => scala....
Peteris's user avatar
  • 3,656
11 votes
1 answer
304 views

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....
dconlon's user avatar
  • 113
1 vote
1 answer
260 views

General enrichment providing "uncurried" in scala

Does there exist a general enrichment for f: A => B => ... => Z in scala/scalaz/shapeless/etc. such that f.uncurried:(A, B, ...) => Z? Currently I have this, but I believe there must be a ...
drstevens's user avatar
  • 2,913
6 votes
3 answers
902 views

"update" method with variable-length index in Scala

I was writing code for something like an array with variable dimensions. What I do is to maintain a linear underlying collections and wrap it up with index access methods. Since the dimension of the ...
Nan Jiang's user avatar
  • 1,314
4 votes
3 answers
1k views

Generically rewriting Scala case classes

Is it possible to generically replace arguments in a case class? More specifically, say I wanted a substitute function that received a "find" case class and a "replace" case class (like the left and ...
Josh Marcus's user avatar
  • 1,739
5 votes
1 answer
378 views

Map on HList in method with Poly1 based on type parameter of class

I have class, parameterized with HList and some other type. How can I use map on HList in one of its methods? Compilation of this code throws java.lang.AssertionError: class Test[L <: HList, P](l:...
senia's user avatar
  • 37.9k
113 votes
4 answers
13k views

Any reason why scala does not explicitly support dependent types?

There are path dependent types and I think it is possible to express almost all the features of such languages as Epigram or Agda in Scala, but I'm wondering why Scala does not support this more ...
Ashkan Kh. Nazary's user avatar
19 votes
5 answers
10k views

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's user avatar
3 votes
2 answers
611 views

Are HList/KList suitable as method parameter? How to refer to? Type List?

I discovered HList / KList, they are pretty cool. I have an actual use case, in which heterogenously typed and variable length containers with conserved type information would be very useful (for more ...
ib84's user avatar
  • 675
3 votes
1 answer
603 views

Scala shapeless KList with extra constraint

I want to take this pattern: def accept[T](a: RList[T]) = true def accept[T, V](a: RList[T], b: RList[V])(implicit ev: a.S =:= b.S) = true def accept[T, V, Q](a: RList[T], b: RList[V], c: RList[Q])...
Heptic's user avatar
  • 3,076
2 votes
1 answer
441 views

selecting a subset of a list of functions based off of the type of their arguments in scala

This is the code in question. Something of a description/explination is included below object Functions { import scala.reflect.Manifest private var functions: List[(Manifest[_],Any,String)] = ...
placeybordeaux's user avatar
8 votes
1 answer
603 views

Method that returns List of size n in Shapeless

Is it possible to make the following code work? def zeroTo[N <: Nat]:Sized[List[Int], N] = { new Sized[List[Int], N](List.iterate(0, toInt[N])(1+)) { type A = Int } } I get a compile ...
Kim Stebel's user avatar
150 votes
4 answers
20k views

Are HLists nothing more than a convoluted way of writing tuples?

I am really interested in finding out where the differences are, and more generally, to identify canonical use cases where HLists cannot be used (or rather, don't yield any benefits over regular lists)...
Malte Schwerhoff's user avatar
2 votes
1 answer
221 views

Replace Asynchronous Anonymous Class with Function

I am thinking this may be possible with the shapeless library. I'm using the shapeless to convert an anonymous class to a closure. This requires the use of hlisted from the FnHListerAux trait. All I ...
Hakkar's user avatar
  • 2,421
7 votes
1 answer
1k views

Unable to map on HList

I was trying to solve this problem with shapeless. However I am for some reason unable to map on the HList. I'll let the code speak for itself. import shapeless._ import HList._ case class Foo(a: ...
missingfaktor's user avatar
5 votes
1 answer
384 views

Why can't I index into an HList obtained by mapping over another HList?

Even .head doesn't work. What changes do I need to make to make this work? import shapeless._ import HList._ import Nat._ scala> case class Foo[A](a: A) defined class Foo scala> case class ...
missingfaktor's user avatar
7 votes
1 answer
2k views

Shapeless : Prepend. Implicit not found

I'm trying to use shapeless to accumulate easily objects in a type safe manner. The problem is when I want to concat (:::) two HList. I'm encountering a newbie (it seems at least) problem. It misses ...
Andy Petrella's user avatar
30 votes
3 answers
5k views

Can Map be performed on a Scala HList

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 ...
Jesse Eichar's user avatar
  • 1,081
43 votes
3 answers
18k views

Use functional combinators on Scala Tuples?

'map' preserves the number of elements, so using it on a Tuple seems sensible. My attempts so far: scala> (3,4).map(_*2) error: value map is not a member of (Int, Int) (3,4).map(_*2) ...
Eldritch Conundrum's user avatar

1
17 18 19 20
21