scala-2.10

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

*爱你&永不变心* 提交于 2019-11-28 09:03:24
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.reflect.runtime.universe._ scala> val t = typeOf[Int] t: reflect.runtime.universe.Type = Int scala> t.typeSymbol.asClass.fullName res0: String = scala.Int scala> object X { class Y } defined module X scala> val y = typeOf[X.Y] y: reflect.runtime.universe.Type = X.Y scala> Class.forName(y.typeSymbol.asClass.fullName) java.lang.ClassNotFoundException: X.Y [...] Am I missing some more direct method of

What is scala's experimental virtual pattern matcher?

耗尽温柔 提交于 2019-11-28 07:09:36
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... llemieng The "virtualized" pattern matcher is a rewrite of the existing matcher. The motivation for doing this was to support virtualization of pattern matching for the polymorphic embedded DSLs , not relevant for 2.10. As Iulian says in the comments below: It's very similar to how for-comprehensions are compiled: instead of directly generating code, they are translated to foreach , map , filter etc. Pattern matching could then be translated to a

Scala Reflection - Loading or finding classes based on trait

核能气质少年 提交于 2019-11-28 04:01:42
问题 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 turn(): Int } class Cog extends Widget { def turn() = { 5 } } class Sprocket extends Widget { def turn() = { 10 } } I want to search the class library for anything that extends Widget and instantiate those classes. So I would end up with an instance of Cog and Sprocket . I've done similar in Java

Scala 2.10 + Json serialization and deserialization

不羁的心 提交于 2019-11-28 03:49:20
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: String, attributes: Map[String, String], friends: List[String]) //to serialize val person = Person("Name", ....) val json = serialize(person) //to deserialize val sameperson = deserialize[Person](json) But I'm having trouble finding good existing ways of generating and deserializing Json that work with Scala 2.10. Are there best practice ways of doing this in Scala 2.10? Jackson is a Java library to

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

馋奶兔 提交于 2019-11-28 03:30:27
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 methods, etc. This is possible with the macro system in 2.10.0, and the type member part is extremely easy: object MacroExample extends ReflectionUtils { import scala.language.experimental.macros import scala.reflect.macros.Context def foo(name: String): Any = macro foo_impl def foo_impl(c: Context)(name: c.Expr[String]) = { import c.universe._ val Literal(Constant(lit: String)) = name.tree val

IntelliJ IDEA Report Highlighting error when using routes in Controller

雨燕双飞 提交于 2019-11-28 03:12:19
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 screenshots): I'm using IntelliJ IDEA 12.1.6 Ultimate version. Scala version 2.10.2 Anybody know how to fix this problem? Thanks in advance! Edit When I generate my project to Intellij IDEA via "play idea" command in play console, and I opened project in IDEA project structure was such: Then I saw answer @millhouse and discussing on this githup( [Play 2.2] "play idea" creates not working source

Custom Scala enum, most elegant version searched

馋奶兔 提交于 2019-11-27 22:13:53
问题 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 } sealed trait Currency extends Currency.Value object Currency extends Enum[Currency] { case object EUR extends Currency case object GBP extends Currency } from Case objects vs Enumerations in Scala. I worked quite nice, till I run into the following problem. Case objects seem to be lazy and if I use Currency.value I

Set the parallelism level for all collections in Scala 2.10?

和自甴很熟 提交于 2019-11-27 16:36:00
问题 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 level for all new parallel collections in Scala 2.10? A subsidiary question --- is the tasksupport associated to a parallel collection 'inherited' by new parallel collections built out of it? (e.g. with take , map , etc.) 回答1: I looked at the sources briefly and if I understand things correctly, there

Enabling the macro-paradise Scala compiler plugin in Maven projects

大城市里の小女人 提交于 2019-11-27 15:07:43
问题 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 scala-2.10 and scala-maven-plugin-3.1.5. 回答1: Looks like I got it to work with the following additions to the pom.xml <repositories> ... <repository> <id>oss.sonatype.org</id> <name>sonatype sapshots</name> <url>https://oss.sonatype.org/content/repositories/snapshots</url> </repository> ... <

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

点点圈 提交于 2019-11-27 12:34:11
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 : String = Hello World I was wondering if there is a way to do dynamic interpolation, e.g. the following (doesn't compile, just for illustration purposes) val name = "World" //> name : String = World val template = "Hello $name" //> template : String = Hello $name //just for illustration: val message = s(template) //> doesn't compile (not found: value s) Is there a way to "dynamically" evaluate a String like that? (or is