As a brief note to self, you compile a TypeScript source code file with the
tsc Foo.ts && node Foo.js
As a note to self, when you see a Scala error message that looks like this:
it probably means that you have a mismatch in the Scala versions you’re using in your project. For instance, I just tried to use a library I compiled with Scala 2.12 with Spark, which was compiled with Scala 2.11, and I got that error message. In this case I was able to resolve the problem by recompiling my library with Scala 2.11.
The image shows how Scala 3 (Dotty) enums expand into other Scala code. I thought that was interesting, and you can learn more at this URL.
I had read that Bloop was faster than Scala compiler tools like
fsc, so I wondered if it was faster than SBT, and if so, how much faster. So I downloaded Eric Torreborre’s specs2 source code, which has 880 source code files, and compiled the entire project with both SBT and Bloop.
To test SBT’s speed, I ran all the commands from inside the SBT command prompt, which I usually do anyway to avoid the SBT/JVM startup lag time. I also ran
compile several times before recording SBT’s speed, because I thought that would be a better reflection of real-world usage and performance. I ran the tests four times, and the average time with SBT was 49 seconds, and that was very consistent, always coming in between 48 and 50 seconds.
As a quick note today, if you’re working on a Scala project and get a compiler error message like this:
Without any explanation, here are a couple of source code examples from my book, Learning Functional Programming in Scala. The only thing I’ll say about this code is that I created it in the process of writing that book, and the examples show how the Scala compiler translates for-expressions into map and flatMap calls behind the scenes.
I recently learned how to use the Java javapackager command to build a macOS application bundle — i.e., a regular macOS application — from a Java application. In this tutorial I’ll show how to create a Mac application bundle from a simple Java class, in this case a Java Swing class.
Answer: Use the
consoleQuick commands inside the SBT shell:
consoleto start a REPL session from inside SBT. This (a) compiles your Scala project and then (b) starts a REPL session.
consoleQuickif you don’t want to compile your project before starting a REPL session inside of SBT.
console command process looks like this:
> sbt [info] Loading project definition from /Users/al/Projects/Cats101/project [info] Set current project to Cats101 (in build file:/Users/al/Projects/Cats101/) > console [info] Starting scala interpreter... [info] Welcome to Scala 2.12.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131). Type in expressions for evaluation. Or try :help. scala> _
If you wanted to see how to start a Scala REPL session from inside SBT, I hope this helps.
This morning I was curious about how Scala curried functions and partially-applied functions are really compiled at a bytecode level. Earlier this morning I made this post that Higher order functions are the Haskell experience — which is also implicitly about curried functions — and it got me thinking about Scala, in particular why we might use one function syntax versus another, i.e., why would I use this syntax: