Alternative to Scala REPL breakIf in 2.10

Perhaps the idea is that you should just work with the ILoop directly? As far as I can tell, it shouldn’t be much more complex than: // insert the code below wherever you want a REPL val repl = new ILoop repl.settings = new Settings repl.in = SimpleReader() repl.createInterpreter() // bind any local variables that … Read more

IntelliJ IDEA Report Highlighting error when using routes in Controller

millhouse’s answer helped me find the right answer. Play 2.2 (and perhaps earlier versions, haven’t checked) output a scala version of the routes file to project_dir/target/scala-2.10/src_managed/main So for IntelliJ to get the highlighting right you need to make sure that src_managed/main is added as a source folder. The reverse routes for javascript are for some … Read more

Scala 2.10 + Json serialization and deserialization

Jackson is a Java library to process JSON fast. The Jerkson project wraps Jackson, but appears to be abandoned. I’ve switched to Jackson’s Scala Module for serialization and deserialization to native Scala data structures. To get it, include the following in your build.sbt: libraryDependencies ++= Seq( “com.fasterxml.jackson.module” %% “jackson-module-scala” % “2.1.3”, … ) Then your … Read more

Map the Exception of a failed Future

There is also: f recover { case cause => throw new Exception(“Something went wrong”, cause) } Since Scala 2.12 you can do: f transform { case s @ Success(_) => s case Failure(cause) => Failure(new Exception(“Something went wrong”, cause)) } or f transform { _.transform(Success(_), cause => Failure(new Exception(“Something went wrong”, cause)))}

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

A lot of things previously defined in package scala.reflect.mirror have moved to scala.reflect.runtime.universe: scala> import scala.reflect.runtime.{universe => u} import scala.reflect.runtime.{universe=>u} scala> val expr = u reify { 1 to 3 map (_+1) } expr: reflect.runtime.universe.Expr[scala.collection.immutable.IndexedSeq[Int]] = Expr[scala.collection.immutable.IndexedSeq[Int]](scala.this.Predef.intWrapper(1).to(3).map(((x$1) => x$1.$plus(1)))(immutable.this.IndexedSeq.canBuildFrom)) scala> u show expr.tree res57: String = scala.this.Predef.intWrapper(1).to(3).map(((x$1) => x$1.$plus(1)))(immutable.this.IndexedSeq.canBuildFrom) scala> u showRaw expr.tree res58: String … Read more

Scala: Parse JSON directly into a case class

There are several frameworks which can exactly do that. circe Used a lot nowdays. Many great features. Will pull cats in. https://circe.github.io/circe/ https://github.com/circe/circe JSON4s JSON4s is quite mature and supports jackson or a native JSON-Parser. Used it in many projects to replace jerkson. https://github.com/json4s/json4s play-json Can be used without the full play stack. Great support … Read more

How to disambiguate links to methods in scaladoc?

The following seems do the trick in Scala 2.10. /** * The most important method is [[Doc.foo[A]:A*]]. */ And here is some hint scaladoc gives me: [warn] Quick crash course on using Scaladoc links [warn] ========================================== [warn] Disambiguating terms and types: Prefix terms with ‘$’ and types with ‘!’ in case both names are in … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)