Questions tagged [implicits]

Anything related to Scala implicit parameters or conversions

Implicits parameters and conversions are a feature of the Scala language. An implicit parameter is one that can be automatically inferred based on its type and the values in scope, without you needing to pass in the value of the argument explicitly. An implicit conversion function converts one type to another automatically on-demand, without needing to call the function explicitly.

170 questions
3
votes
2 answers

Could not find implicit value for parameter ordering

I get the following error when trying to compile this: Btree.scala:9: error: could not find implicit value for parameter ordering: Ordering[K] abstract class Node[K,V] extends TreeMap[K,V] TreeMap is supposed to accept an implicit…
3
votes
3 answers

Constructing an overridable implicit

I would like to implement a generic implicit for a class that can be overriden. As following: tooling.scala package tooling case class Tool( msg: String) class Toolkit{ def usingTool(source:String)(implicit tool:Tool){ println(…
dstibbe
  • 1,589
  • 18
  • 33
3
votes
1 answer

Implicit conversions, type parameters, overloading, and anonymous functions syntax

So, I was trying to "pimp" my Futures (among other things) a little bit with something like this: implicit class Pimp[T](val x: T) extends AnyVal { def ->>[R](f: T => R): R = f(x) def ->>[R](r: => R): R = r def <<-(f: T => Unit): T =…
Dima
  • 39,570
  • 6
  • 44
  • 70
3
votes
2 answers

Shapeless HList polymorphic map with an argument

Given an HList of Label[A](String) I want to map it into an HList of LabelWithValue[A](Label[A], A), where the actual values come from a Map[String, Any]. In the example below I just defined the map of values in the method, just imagine the values…
Michael Pollmeier
  • 1,370
  • 11
  • 20
3
votes
1 answer

Scala shapeless: derive type from Mapper

The method doesNotCompile accepts only HLists that contain only Label[A] entries. There is a Mapper that transforms a Label[A] to a String (to be precise: Const[String]#λ). However when I apply the mapper, the return type is ev1.Out. I know that's…
Michael Pollmeier
  • 1,370
  • 11
  • 20
3
votes
1 answer

Implicit search does not guide type inference to find a supertype in Scala

I the following code, I have evidence of R[A] and B is a subtype of A, so I would expect foo to infer the type of A and use the RA evidence. However, scalac refuses to do so. trait R[T] case class A(i: Int) object A { implicit object RA extends…
3
votes
3 answers

scala implicit class method type mismatch in reduce vs non-implicit method with function currying

Problem: Something about implicit class, confuses reduce(). When inside implicit class, compiler complains on reduce() second parameter. but when same code is inside non-implicit method it compiles and works fine. What am I missing about implicit…
Michael Zeltser
  • 399
  • 1
  • 3
  • 7
3
votes
2 answers

Clean up signatures with long implicit parameter lists

Is there an elegant solution to somehow clean up implicit parameter lists making signatures more concise? I have code like this: import shapeless._ import shapeless.HList._ import shapeless.ops.hlist._ import shapeless.poly._ trait T[I, O] extends…
ponythewhite
  • 617
  • 3
  • 8
3
votes
1 answer

play json writes subclass gives ambiguous implicit values error

I'm using the play framework, and have an abstract class: abstract class Base{...} which has its own implicit JSON writer within the companion object object Base { implicit val baseWrites: Writes[Base] = (...)(unlift(Base.unapply)) } I…
jb44
  • 393
  • 1
  • 6
  • 23
3
votes
1 answer

Scala spray-client define implicits for AKKA ActorRefFactory

I'm trying to write a simple HTTP client using Scala and spray-client. I'm basing my client on the examples given on Spray docs. My issue is that the example is creating a new implicit ActorSystem i.e. implicit val system = ActorSystem() but I want…
Ayub Malik
  • 2,488
  • 6
  • 27
  • 42
3
votes
2 answers

How to be able to apply implict conversions in a recursive way in Scala

I am trying to write a conversions library for converting some scala types to an HTML representation. I would want, say, to execute List(1,2).toHtml and obtain
  • 1
  • 2
, as a String. So far i've written a set of implicit…
vascase
  • 45
  • 4
2
votes
0 answers

Why does extracting and assigning individual tuple values cause a recursive implicit search?

Here's the code to produce this error: build.sbt scalaVersion := "2.11.7" libraryDependencies ++= Seq( "ai.x" %% "safe" % "0.1.0" ) scalacOptions := Seq("-Ytyper-debug") // Only add this if you want to see a bunch of stuff test.scala import…
EdgeCaseBerg
  • 2,761
  • 1
  • 23
  • 39
2
votes
2 answers

Test two scala shapeless HList types for equivalence via implicit

I'm interested in testing whether two HList heterogeneous records are "equivalent"; that is, they have the same key/val pairs, but not necessarily in the same order. Is there a predefined type predicate that does what EquivHLists does in the code…
eje
  • 945
  • 11
  • 22
2
votes
0 answers

Powerset of an HList of Options

I am playing around with Shapeless and I am trying to compute the (kind-of) powerset of an HList of Options. Basically, I want to interpret the HList as a set, in which case the Option value of an element tells me it belongs to the set or not. For…
mdm
  • 3,928
  • 3
  • 27
  • 43
2
votes
0 answers

Why doesn't implicit conversion work here?

Given, trait GetOrElseAble[Container[_]] { def getOrElse[A](one : Container[A], two : A) : A } And, implicit val optionGetOrElseAble = new GetOrElseAble[Option] { override def getOrElse[A](one: Option[A], two: A): A =…
Dhruv Kapur
  • 726
  • 1
  • 8
  • 24