Questions tagged [scala-2.10]

Version 2.10 of the Scala language for the JVM. Use only if your question is specifically related to features of this version.

scala-2.10
Filter by
Sorted by
Tagged with
384 votes
1 answer
80k views

What is a TypeTag and how do I use it?

All I know about TypeTags is that they somehow replaced Manifests. Information on the Internet is scarce and doesn't provide me with a good sense of the subject. So I'd be happy if someone shared a ...
Sergey Weiss's user avatar
  • 5,964
64 votes
3 answers
40k views

Scala's "postfix ops"

I've searched for a half-hour, and still cannot figure it out. In SIP: Modularizing Language Features there are a number of features which will require explicit "enabling" in Scala 2.10 (import ...
dmitry's user avatar
  • 5,019
45 votes
1 answer
14k views

Generating a class from string and instantiating it in Scala 2.10

In Scala 2.10 how do I generate a class from string (probably, using the Toolbox api) later to be instantiated with Scala's reflection?
Nikita Volkov's user avatar
22 votes
2 answers
5k views

Finding type parameters via reflection in Scala 2.10?

Using type tags, I'm able to see the parameters of some type: scala> import scala.reflect.runtime.universe._ import scala.reflect.runtime.universe._ scala> typeOf[List[Int]] res0: reflect....
Tim's user avatar
  • 1,655
23 votes
2 answers
5k views

How to get ClassTag form TypeTag, or both at same time?

I have some code like this: class ReflectiveJsonFormat[T:TypeTag] extends JsonFormat[T] { def write(x: T) : JsValue = { val t = typeOf[T] val getters = t.declarations.filter { s => s....
Rob N's user avatar
  • 15.7k
19 votes
2 answers
5k views

How do I access default parameter values via Scala reflection?

Let's say a I have a class: case class Foo(id: Int, name: String, note: Option[String] = None) Both the constructor and the apply method in the automatically generated companion object take three ...
Erik Engbrecht's user avatar
76 votes
1 answer
20k views

Use case of scala.concurrent.blocking

I came across the scala.concurrent.blocking method, and according to the Scala documentation this is... Used to designate a piece of code which potentially blocks, allowing the current BlockContext ...
Sourav Chandra's user avatar
38 votes
2 answers
10k views

What's the easiest way to use reify (get an AST of) an expression in Scala?

I'm looking at alternatives to -print or javap as a way of figuring out what the compiler is doing in Scala. With the new reflection/macros library, reify seems a good candidate for that, as shown in ...
Daniel C. Sobral's user avatar
42 votes
1 answer
4k views

Static return type of Scala macros

So I've got this macro: import language.experimental.macros import scala.reflect.macros.Context class Foo class Bar extends Foo { def launchMissiles = "launching" } object FooExample { def foo: ...
Travis Brown's user avatar
8 votes
2 answers
1k views

Creating a method definition tree from a method symbol and a body

Is there a convenient way to turn a MethodSymbol into the left-hand side of a method definition tree (i.e., a DefDef) in Scala 2.10? For example, suppose I want to create a macro that will take an ...
Travis Brown's user avatar
84 votes
1 answer
32k views

Scala generic method - No ClassTag available for T

I'm relatively new to Scala and am trying to define a generic object method. However, when I refer to the parameterized type within the method I am getting "No ClassTag available for T". Here is a ...
Chuck's user avatar
  • 1,870
30 votes
2 answers
15k views

Scala 2.10 reflection, how do I extract the field values from a case class, i.e. field list from case class

How can I extract the field values from a case class in scala using the new reflection model in scala 2.10? For example, using the below doesn't pull out the field methods def getMethods[T:TypeTag](...
J Pullar's user avatar
  • 1,925
21 votes
4 answers
9k views

How to know if an object is an instance of a TypeTag's type?

I have a function which is able to know if an object is an instance of a Manifest's type. I would like to migrate it to a TypeTag version. The old function is the following one: def myIsInstanceOf[T: ...
neutropolis's user avatar
  • 1,884
37 votes
5 answers
44k views

Scala 2.10 + Json serialization and deserialization

Scala 2.10 seems to have broken some of the old libraries (at least for the time being) like Jerkson and lift-json. The target usability is as follows: case class Person(name: String, height: ...
user1698607's user avatar
17 votes
2 answers
2k views

How are lazy val class variables implemented in Scala 2.10?

This answer to What's the (hidden) cost of Scala's lazy val? shows how they were implemented in Scala 2.7. But as the comments say, this must have changed since then, so I'm curious, what's the ...
Petr's user avatar
  • 63.1k
181 votes
1 answer
9k views

Getting a structural type with an anonymous class's methods from a macro

Suppose we want to write a macro that defines an anonymous class with some type members or methods, and then creates an instance of that class that's statically typed as a structural type with those ...
Travis Brown's user avatar
50 votes
4 answers
13k views

String interpolation in Scala 2.10 - How to interpolate a String variable?

String interpolation is available in Scala starting Scala 2.10 This is the basic example val name = "World" //> name : String = World val message = s"Hello $name" //> message ...
Eran Medan's user avatar
  • 45.3k
43 votes
2 answers
3k views

What is scala's experimental virtual pattern matcher?

I've seen quite a few mentions recently of the new "virtualized" pattern matcher for scala. I missed the memo explaining what it actually was...
oxbow_lakes's user avatar
35 votes
2 answers
7k views

IntelliJ IDEA Report Highlighting error when using routes in Controller

I have a Scala Play project. I'm using Play 2.2.1. I downloaded Scala, Play 2 supported and SBT plugins. Everything is OK, but When I call route on Action in the Controller appear following error(Look ...
SBotirov's user avatar
  • 14k
26 votes
2 answers
13k views

Scala Constructor Parameters

What is the difference between a private var constructor parameter and a constructor parameter without val/var? Are they same in terms of scope/visibility? Ex: class Person(private var firstName:...
user2456976's user avatar
  • 1,298
25 votes
7 answers
34k views

How to remove an item from a list in Scala having only its index?

I have a list as follows: val internalIdList: List[Int] = List() internalIdList = List(11, 12, 13, 14, 15) From this list would remove the third element in order to obtain: internalIdList = List(...
YoBre's user avatar
  • 2,530
20 votes
2 answers
8k views

Any way to obtain a Java class from a Scala (2.10) type tag or symbol?

Looks like this gets me close, but (a) not quite (see below), and (b) using the string representation of a name feels like a hack... scala> import scala.reflect.runtime.universe._import scala....
Tim's user avatar
  • 1,655
12 votes
4 answers
12k views

Scala error: class file is broken, bad constant pool index

I'm trying to call the Selenium Java libraries from Scala. I'm using Scala IDE (Eclipse), and Scala 2.10.2. What is causing this compiler error? error while loading Function, class file '/Dev/...
Rob N's user avatar
  • 15.7k
7 votes
3 answers
4k views

converting Akka's Future[A] to Future[Either[Exception,A]]

Is there a method in Akka (or in the standard library in Scala 2.10) to convert a Future[A] which might fail into a Future[Either[Exception,A]]? I know that you can write f.map(Right(_)).recover { ...
Kim Stebel's user avatar
48 votes
2 answers
15k views

How do you update multiple columns using Slick Lifted Embedding?

How do you update multiple columns using Slick Lifted Embedding ? This document doesn't say much. I expected it to be something like this Query(AbilitiesTable).filter((ab: AbilitiesTable.type) => ...
expert's user avatar
  • 29.7k
16 votes
7 answers
16k views

Flatten Scala Try

Is there a simple way to flatten a collection of try's to give either a success of the try values, or just the failure? For example: def map(l:List[Int]) = l map { case 4 => Failure(new ...
J Pullar's user avatar
  • 1,925
13 votes
2 answers
5k views

Enabling the macro-paradise Scala compiler plugin in Maven projects

I have the ordinary scala-2.10 macros working in a maven project just by including the scala-reflect.jar library as a dependency in the pom, but what do I need to turn on macro-paradise? I am using ...
Daniel Mahler's user avatar
11 votes
3 answers
3k views

Custom Scala enum, most elegant version searched

For a project of mine I have implemented a Enum based upon trait Enum[A] { trait Value { self: A => _values :+= this } private var _values = List.empty[A] def values = _values } ...
vchuravy's user avatar
  • 1,218
10 votes
1 answer
3k views

Set the parallelism level for all collections in Scala 2.10?

I understand how to set the parallelism level for a single parallel collection, via the mutable tasksupport field (c.f. https://stackoverflow.com/a/5425354/82970). How can I set the parallelism ...
Scott Morrison's user avatar
8 votes
1 answer
8k views

Scala Reflection - Loading or finding classes based on trait

Does the scala reflection API (2.10) provide any easier means of searching the loaded classes and filtering the list to specific classes which implement a defined trait? ie; trait Widget { def ...
Doswell's user avatar
  • 418
6 votes
3 answers
2k views

Scala macro to print code?

I want to do something like this: def assuming[A](condition: => Boolean)(f: => A): A = { require(condition, /* print source-code of condition */) f } Sample usage: def fib(n: Int) = n ...
pathikrit's user avatar
  • 33.2k
5 votes
2 answers
2k views

scala macros: Add function to class

I'm new to scala macros and I'm using scala 2.10.0-RC3. I want to write a macro that adds a function to a class. Usage example: trait MyTrait { def addF = macro { /*add "def f = 3" to class*/ } } ...
Heinzi's user avatar
  • 5,933
4 votes
3 answers
2k views

Option.fold in scala 2.10

In the following session with scala 2.10.0-M7: scala> trait A defined trait A scala> class B extends A defined class B scala> class C extends A defined class C scala> Some(0).fold(new B){...
venechka's user avatar
  • 1,234
72 votes
1 answer
2k views

Documenting Scala 2.10 macros [closed]

I'll start with an example. Here's an equivalent of List.fill for tuples as a macro in Scala 2.10: import scala.language.experimental.macros import scala.reflect.macros.Context object TupleExample { ...
Travis Brown's user avatar
40 votes
7 answers
66k views

Scala: Parse JSON directly into a case class

Given a string of JSON, and a case class that corresponds to it, what's a simple way to parse the JSON into the case class? There are many libraries available, but it seems that Scala might now do ...
SRobertJames's user avatar
  • 8,791
38 votes
2 answers
28k views

Map the Exception of a failed Future

What's the cleanest way to map the Exception of a failed Future in scala? Say I have: import scala.concurrent._ import scala.concurrent.ExecutionContext.Implicits.global val f = Future { if(math....
theon's user avatar
  • 14.3k
28 votes
1 answer
4k views

How do the new Scala TypeTags improve the (deprecated) Manifests? [duplicate]

Possible Duplicate: Scala 2.10: What is a TypeTag and how do I use it? I have been reading about the new TypeTags which come along with the new reflection api. It seems that Manifests are ...
neutropolis's user avatar
  • 1,884
21 votes
5 answers
8k views

Is it possible to use IN clause in plain sql Slick?

For example, I want to create the following query: SELECT c.* FROM Coffees c WHERE c.name IN ('robusta', 'arabica') My attempt failed: val cnames = List("robusta", "arabica") sql""" SELECT c.* FROM ...
Rogach's user avatar
  • 26.7k
19 votes
2 answers
4k views

How do I print an expanded macro in Scala?

I am writing a macro in Scala, but when I call it I get an error message saying "Double does not take parameters". Clearly there is something wrong with how the macro builds the AST. So how can I see ...
Kim Stebel's user avatar
17 votes
3 answers
6k views

What does "reflective access of structural type member method should be enabled..." warning mean in Scala?

After switching to Scala 2.10 I get tons of warnings: reflective access of structural type member method ... should be enabled by making the implicit value language.reflectiveCalls visible What ...
Ivan's user avatar
  • 63.6k
17 votes
1 answer
7k views

Is using Try[Unit] the proper way?

I recently came across the concept of Try/Success/Failure, and I am wondering how to use it for a method that has the return type Unit. Is using Try[Unit] the correct way? Maybe I am too influenced ...
Karda's user avatar
  • 313
13 votes
1 answer
3k views

How do I set the default number of threads for Scala 2.10 parallel collections?

In Scala before 2.10, I can set the parallelism in the defaultForkJoinPool (as in this answer scala parallel collections degree of parallelism). In Scala 2.10, that API no longer exists. It is well ...
JZeta's user avatar
  • 163
12 votes
1 answer
11k views

How do I format a string with string interpolation in Scala as a fixed width string?

I'm interfacing with a really old system and the file I need to generate needs a field that is a formed from a string but needs to be exactly 15 in width. I want something like this: val companyName ...
myyk's user avatar
  • 1,548
12 votes
2 answers
2k views

Is it possible to convert a TypeTag to a Manifest?

Our library uses TypeTags, but now we need to interact with another library which requires Manifests. Is there any simple way to create a Manifest from a TypeTag?
Alexey Romanov's user avatar
11 votes
2 answers
5k views

How to write a Play JSON writes converter for a case class with a single nullable member

In Play 2.3, I have a case class with a single optional double member: case class SomeClass(foo: Option[Double]) I need a JSON write converter that handles the member as nullable: implicit val ...
Lasf's user avatar
  • 2,563
10 votes
1 answer
2k views

How can I get the actual object referred to by Scala 2.10 reflection?

Please consider this code: object ResponseType extends Enumeration { val Listing, Album = Value } I can get the Symbol referring to this object like so: import reflect.runtime.universe._ val s = ...
Nikita Volkov's user avatar
10 votes
3 answers
5k views

Scala Play 2.2 application crashes after deploying in Heroku: target/start No such file or directory

I've been fighting with this for hours and I can't figure out why after deploying my Scala Play 2.2 application in Heroku I get this stacktrace: 2013-09-30T01:05:09.413177+00:00 heroku[web.1]: ...
Carla's user avatar
  • 205
9 votes
1 answer
2k views

Can this free-term-variable error (produced at macro expansion) be avoided?

I am developing a DSL and I am getting a "free term" failure while expanding a macro. I would like to know if it can be avoided. I have simplified the problem to the following situation. Suppose we ...
neutropolis's user avatar
  • 1,884
9 votes
3 answers
5k views

Kill or timeout a Future in Scala 2.10

Hi, I'm using Scala 2.10 with the new futures library and I'm trying to write some code to test an infinite loop. I use a scala.concurrent.Future to run the code with the loop in a separate thread. I ...
Stephan's user avatar
  • 191
8 votes
3 answers
4k views

Using Scala 2.10 reflection how can I list the values of Enumeration?

Having a following enumeration object ResponseType extends Enumeration { val Listing, Album = Value } How do I get a list of its vals?
Nikita Volkov's user avatar