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

generic SortByValue based on Numeric

How do I create one implicit class for both use cases? implicit class SortableByIntValue(rdd:RDD[(String,Int)]){ def sortByValue = rdd.sortBy(_._2) } implicit class SortableByDoubleValue(rdd:RDD[(String,Double)]){ def sortByValue =…
Walrus the Cat
  • 2,314
  • 5
  • 35
  • 64
0
votes
1 answer

Call method with implicit argument where type is only known at runtime

Say I have a method like this: def doSomething(a : A)(implicit someTrait : SomeTrait[A]) : B = { ... } I call a Java method that gives me an AnyRef back and I want to pass the returned object to doSomething: val obj : AnyRef =…
mushroom
  • 6,201
  • 5
  • 36
  • 63
0
votes
3 answers

unclear why my in-scope implicit conversions are not accepted as 'implicit evidence'

I've been experimenting with implicit conversions, and I have a decent understanding of the 'enrich-my-libray' pattern that uses these. I tried to combine my understanding of basic implicits with the use of implicit evidence... But I'm…
Chris Bedford
  • 2,560
  • 3
  • 28
  • 60
0
votes
1 answer

Context bound for nested type

Is it possible to create somehow a context bound for a nested type? Something like this: def f[T : U[List]](a: T) Ofc, this is not Scala syntax, but illustrates what I want to achieve, that is, get a bound on an implicit U[List[T]]. Is this…
ale64bit
  • 6,232
  • 3
  • 24
  • 44
0
votes
1 answer

Scala implicit natural transform with monad failing to find functions for for comprehension

The code I have is this: class SourceService[Out[+_]](implicit monad:Monad[Out]) { def doSomething:Out[String] = monad.point("Result") } class SimplifiedPipe[Out[+_], In[+_]] (myService:SourceService[In]) (implicit monad:Monad[Out], pipe:…
J Pullar
  • 1,915
  • 2
  • 18
  • 30
0
votes
1 answer

Arranging implicits precedence in Scala

Consider the following (working) snippet that defines bidirectional implicit conversions between the DenseVector and Arrays: import scala.reflect.ClassTag import org.apache.spark.mllib.linalg.Vectors import breeze.linalg.{DenseVector => BDV} …
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
0
votes
0 answers

Implicit resolution in descendants of associated types to avoid import tax

class JavaRxObservable class MyObservable extends JavaRxObservable object MyObservable { implicit class ObservablePimp(o: JavaRxObservable) { def flatMapPimp: JavaRxObservable = ... } } def api: JavaRxObservable = new…
lisak
  • 21,611
  • 40
  • 152
  • 243
0
votes
1 answer

Restrict method of a trait with constraint on abstract type member using implicits?

I am in the situation below: import scalaz.Leibniz._ trait Exp[T, C] { def &&(that: Exp[T, C])(implicit evT: T === Boolean) = LogicalAnd(this, that) def &&(that: Exp[T, C])(implicit evT: T === Int) = BitwiseAnd(this, that) } case class…
remi
  • 566
  • 3
  • 13
0
votes
1 answer

Scala and implicit class instantiation

I have the following two Scala files: object ImplicitsHome { implicit class StringWrapper(val str: String) extends ImplicitsHome with Serializable } trait ImplicitsHome { def str: String def embelishString: String = { …
jcm
  • 5,499
  • 11
  • 49
  • 78
0
votes
1 answer

Ambiguous Class level and inherited method level ClassTag

I have a trait that requires a function with a ClassTag trait Foo[T] { def bar(a: List[T])(implicit ev: ClassTag[T]): Unit } Now I have a class that needs to extend that trait, but it also has uses for its ClassTag for other methods, e.g. class…
kanielc
  • 1,268
  • 1
  • 12
  • 14
0
votes
1 answer

How is Playframework's Session injected into the Action?

I am trying to write my own action and pass in a DatabaseSession implicitly. However, at best I can do something like this in my controller. def index = MyAction { implicit myRequest => implicit val dbss = myRequest.databaseSession …
Roy Lin
  • 730
  • 8
  • 17
0
votes
1 answer

Implicit resolution and their parameter type inference in scala

Are there any good sources on how implicit resolution works, especially regarding type inference and order (if any) in which implicits are searched for all implicit parameters? First, of course I read Scala Language Specification, so I understand…
Turin
  • 2,208
  • 15
  • 23
0
votes
2 answers

Find implicit value by abstract type member

With a type like trait A[T], finding an implicit in scope is simply implicitly[A[SomeType]] Can this be done and, if so, how is this done where the type-parameter is replaced with an abstract type member, like in trait A { type T }?
megri
  • 1,019
  • 8
  • 10
0
votes
3 answers

Which implicit conversions in Scala are present as default when nothing is imported

Which implicits are present by default in Scala? I know of RichString, Regex and some others I use. But is there a list of them all? Where are they implemented ? SourceFiles? Is there a way to get a list of all possible implicit conversions for the…
Andreas Neumann
  • 10,734
  • 1
  • 32
  • 52
0
votes
1 answer

Better workaround for implicits and ordering issues, while serializing to JSON with Spray?

I'm using the Spray JSON library to serialize our case classes into JSON. The problem is that we have some mutually recursive definitions. I am working from the example for serializing sealed traits…
1 2 3
11
12