def and var in traits on Scala 2.12, 2.13 and 3.0.0

Scala traits should define defs, because “A val can override a def, but a def cannot override a val” (via Alvin Alexander via StackOverflow). But it’s interesting to look at how the compiler treats that. Alvin Alexander did that, but only for Scala 2.12.8. Let’s have a look at 2.12, 2.13 and the just released 3.0 (formerly known as dotty). ...

April 24, 2021 · Jannik Arndt

Using scalap, javap and the scala compiler to understand the journey from code to bytecode

Do you know what happens after you compile? Let’s take a look at what the Scala compiler tells us, and what scalap and javap can reveal about .class files. ...

March 25, 2021 · Jannik Arndt

Exception-Proof For-Comprehensions

I recently created a wonderful bug. ...

December 4, 2018 · Jannik Arndt

oAuth2 with Akka HTTP

This is a basic example how to implement oAuth2 using Akka HTTP and Scala. It provides three endpoints. From the clients point of view: / — publicly accessible, returns “Welcome!”, /auth — provide your username and password, receive an access_token in return, /api — secured by oAuth, send the access_token in a header to gain access. From the server’s point of view: / — publicly accessible, do nothing, /auth — receive basic auth credentials, verify they’re in the list of known credentials, create an access_token, return it, /api — receive authorization header, check if access_token is in list of valid tokens. Since oAuth tokens are short lived, the server also has to invalidate expired tokens. ...

October 28, 2018 · Jannik Arndt

Akka HTTP on Heroku

Getting a Akka HTTP-based backend up and running on Heroku for free can be done in less then 30 minutes — if you know the tricks. ...

October 27, 2018 · Jannik Arndt

How to Write and Test a Reactive Reader for AWS SQS Using akka, alpakka and Localstack

This example show how to write a reactive reader for the AWS Simple Queue Service, using Scala and alpakka (respective akka streams). ...

October 7, 2018 · Jannik Arndt

How Event Sourcing in Akka Persistent Actors Works

While the Akka documentation is incredibly well written, it has surprisingly few images. Since I visualize concepts to remember them, here is my take on how Event Sourcing in Akka Persistence works: ...

August 31, 2018 · Jannik Arndt

Releasing a Scala + Maven project to Maven Central (Sonatype OSS)

If you write Scala in a Java-centric environment, chances are you might wind up with a Maven project, defined in a pom.xml. While this can work, it brings a few extra caveats if you want to submit your project to Maven Central (aka Sonatype OSSRH). Step 1: Claim your Group ID When you first publish something to the Sonatype OSSRH, you have to create a JIRA account and then create a ticket for a new project....

September 10, 2017 · Jannik Arndt

Writing case classes to MongoDB in Scala

Storing case classes in a MongoDB database is incredibly easy, once you know how. The same goes for java.time classes such as ZonedDateTime, LocalDate or Duration. This example uses the official Mongo Scala Driver in version 2.x and the bsoncodec project by Ralph Schaer. ...

August 19, 2017 · Jannik Arndt