SBT stop run without exiting

From sbt version 0.13.5 you can add to your build.sbt cancelable in Global := true It is defined as “Enables (true) or disables (false) the ability to interrupt task execution with CTRL+C.” in the Keys definition If you are using Scala 2.12.7+ you can also cancel the compilation with CTRL+C. Reference https://github.com/scala/scala/pull/6479 There are some … Read more

Are HLists nothing more than a convoluted way of writing tuples?

Addressing questions one to three: one of the main applications for HLists is abstracting over arity. Arity is typically statically known at any given use site of an abstraction, but varies from site to site. Take this, from shapeless’s examples, def flatten[T <: Product, L <: HList](t : T) (implicit hl : HListerAux[T, L], flatten … Read more

How to sort by column in descending order in Spark SQL?

You can also sort the column by importing the spark sql functions import org.apache.spark.sql.functions._ df.orderBy(asc(“col1”)) Or import org.apache.spark.sql.functions._ df.sort(desc(“col1″)) importing sqlContext.implicits._ import sqlContext.implicits._ df.orderBy($”col1″.desc) Or import sqlContext.implicits._ df.sort($”col1”.desc)

Scala: write string to file in one statement

It is strange that no one had suggested NIO.2 operations (available since Java 7): import java.nio.file.{Paths, Files} import java.nio.charset.StandardCharsets Files.write(Paths.get(“file.txt”), “file contents”.getBytes(StandardCharsets.UTF_8)) I think this is by far the simplest and easiest and most idiomatic way, and it does not need any dependencies sans Java itself.

How do I cast a variable in Scala?

The preferred technique is to use pattern matching. This allows you to gracefully handle the case that the value in question is not of the given type: g match { case g2: Graphics2D => g2 case _ => throw new ClassCastException } This block replicates the semantics of the asInstanceOf[Graphics2D] method, but with greater flexibility. … Read more

Is there a reason not to use SparkContext.getOrCreate when writing a spark job?

TL;DR There are many legitimate applications of the getOrCreate methods but attempt to find a loophole to perform map-side joins is not one of them. In general there is nothing deeply wrong with SparkContext.getOrCreate. The method has its applications, and although there some caveats, most notably: In its simplest form it doesn’t allow you to … Read more

Scala3: Crafting Types Through Metaprogramming?

Just in case, here is what I meant by hiding ViewOf inside a type class (type classes is an alternative to match types). Sadly, in Scala 3 this is wordy. (version 1) import scala.annotation.experimental import scala.quoted.{Expr, Quotes, Type, quotes} // Library part trait View extends Selectable { def applyDynamic(key: String)(args: Any*): Any = { println(s”$key … Read more

Play: How to implement action composition

Function async is expecting a Future[SimpleResult], but the nested SecuredAction.async is returning an Action to the top SignedAction.async (notes that in your sample code you omit to declare requests as class and SignedAction is declared twice). You can compose result of nested SecuredAction within SignedAction by applying it to the signed request. package controllers import … Read more