Questions tagged [implicit-parameters]

28 questions
1
vote
1 answer

Implicit parameters at the same scope in other files

Reviewing implicit parameters (and conversions) precedence rules at http://docs.scala-lang.org/tutorials/FAQ/finding-implicits.html I found the following priority list: First look in current scope Implicits defined in current scope Explicit…
1
vote
2 answers

Scala capture all implicits of the calling scope?

Suppose I have a scope A in which some implicit values are defined, and a code block c that uses those implicit values. I also have scope B which has implicits of compatible type, so that if I copy the code block c into B, it would compile and run…
geoffliu
  • 510
  • 3
  • 10
1
vote
2 answers

Can an implicit conversion of an implicit value satisfy an implicit parameter?

I'm defining some Scala implicits to make working with a particular unchangeable set of Java classes easier. The following Scala code is a simplified example that obviously looks crazy, in the real world I'm trying to grab particular resources…
Roberto Tyley
  • 24,513
  • 11
  • 72
  • 101
0
votes
1 answer

How to write an implicit Numeric for a tuple

I have a scenario where I would like to call sum on a sequence of (Double, Double) tuples. Ideally I would like to do something like the following: implicit def toTupleNumeric[T](num: Numeric[T]) = new Numeric[(T, T)] { def plus(x: (T, T), y:…
0
votes
1 answer

return object instance instead of function return in java (implicit parameter)

I would like to set a rectangle position relative to another component, but offsetted. I tried the following: rndRect.setLocation(StartButt.getLocation().translate(buttW, 2)); but translate returns void, so it is not accepted as a parameter…
0
votes
1 answer

How to instantiate a class by name in Scala which requires an implicit parameter?

I have a class declared like this: class XYZ(implicit sys: ActorSystem) extends Enricher { } In a function, I am instantiating the class using the name of the class(here: className). I tried to do it like this: val clazz =…
white-hawk-73
  • 856
  • 2
  • 10
  • 24
0
votes
1 answer

Error in lifting method to function

I have a method that with the implicit parameter. i get a error when i convert it to function in 2 case : 1: def action(implicit i:Int) = i + " in action" val f = action _ then i get a StackOverflowError. 2: def action(implicit i:Int) = i + "…
Milk
  • 103
  • 1
  • 10
0
votes
1 answer

Scala: How to override implicit constructor parameters?

I am currently working on a little scala DSL for Android (https://github.com/bertderbecker/scalandroid). val drawerLayout = new SDrawerLayout { openDrawerFrom = SGravity.LEFT fitsSystemWindows = true navigationView = new SNavigationView…
0
votes
1 answer

On the readability of implicit parameters

All methods in my DAO class that handles folders (the web application is about cloud storage, like google drive) has User as first parameter. This parameter is used so that the current user may only access folders that he or she owns. Some of…
Mironor
  • 1,157
  • 10
  • 25
0
votes
1 answer

How to reference implicit parameters in a where closure

How can I use an implicit parameter inside a where closure? I'm not especially proud of my current workaround: def index() { def params = params // <-- UGLY HACK respond Project.where { if (params.sender) { …
Tobia
  • 17,856
  • 6
  • 74
  • 93
0
votes
1 answer

Implicit parameters and NullPointerException in Scala

I am trying to define a function that takes an integer and an implicit object that has the code to process that number, but i get a NullPointerException and i don know why. If I delete the first println the code works. Is there some problem with…
Agustin
  • 41
  • 4
0
votes
1 answer

Scala: Intercept functions to provide implicit parameters with Akka Futures

Ok, so I have a series of calls to functions that return Akka Futures, and I'm chaining them by using flatMap and map like so: doAsyncCall(..).flatMap { res1 => doAsyncCall2(..).flatMap { res2 => doAsyncCall3(..).map { res3 => res } …
Diego
  • 5,024
  • 6
  • 38
  • 47
-1
votes
1 answer

Why does Scala prefer implicit parameters over extending a trait?

Scala ordering API uses implicit objects. e.g.: def msort[T](xs: List[T])(implicit ord: Ordering) = { ...} Java uses Comparable interface for the same purpose. public static > void sort(List list) { ... } Why…
user1552545
  • 1,233
  • 3
  • 15
  • 33
1
2