Context functions are one of the new contextual abstractions coming in Scala 3. The release is approaching quickly, the design is finalized, so let’s explore the feature in more detail!
If you’d prefer a live-coding video version, see the recent Scala In The City meetup on the same topic.
Before we dive into usage examples and consider why you would be at all interested in using context functions, let’s see what they are and how to use them.
A regular function can be written in Scala in the following way:
val f: Int => String = (x: Int) => s"Got…
It features the challenge mode, where through a series of step-by-step tutorials you can learn both the Shelly language, as well as the basics of programming. There’s also the creative mode, where you can draw whatever you like, and share it with others as an image, code (to allow modifications), or as a custom challenge — can others reproduce your painting?
Shelly delivers the well-known concept of turtle graphics in a modern package, with a friendly interface, instant drawing, rich…
The serverless model has a lot of appeal: simple to deploy, simple to scale, no hardware to manage, and no upfront financial commitments. However, we have to realize that using a serverless platform is in fact programming the [Amazon|Google|Microsoft] “virtual machine” which is induced by the myriad of services each of these clouds offers.
Nowadays, this programming is most often done using YAML. Opinions vary whether that’s a good direction. …
We can’t trust the data that reaches our servers. We have to make sure that it’s properly formatted, within range, that it references entities that exist in the database, or that the data matches dynamically defined business rules. A wide range of responsibility!
That’s why we need data parsers & validators. Frameworks and libraries try to help us with that task by defining various extension points where we can plug in our validation rules. But where to draw the line: when to perform what kind of validations? How much parsing & validation should be done outside the service layer (e.g…
After a long series of RC releases, many planned and unplanned changes, the 3.0.0 release is here. Let’s take a brief look at what’s new & changed.
It’s the Scala HTTP client that you always wanted! More elaborately, quoting the documentation:
sttp client is an open-source library which provides a clean, programmer-friendly API to describe HTTP requests and how to handle responses. Requests are sent using one of the backends, which wrap other Scala or Java HTTP client implementations. The backends can integrate with a variety of Scala stacks, providing both synchronous and asynchronous, procedural and functional interfaces.
Let’s apply functional programming to a practical problem. Can you guess what it’s going to be?
We’ll walk step-by-step through the implementation of a simple web socket application, written using “functional” libraries. All of the code is on GitHub, if you’d like to follow having the code in your favorite IDE!
Here are the ingredients that we are going to use:
Tapir is a library for describing HTTP endpoints as immutable values, using a type-safe, composable API. Until recently, tapir’s main functionalities included the ability to describe “regular” REST-like endpoints, and interpret these descriptions as a server, client or OpenAPI documentation.
One of the most-voted feature request was web socket support, and here it is, in version 0.17! It is now possible to describe a web socket endpoint, expose it as an akka-http or http4s server, interpret as an sttp client, or generate AsyncAPI documentation!
Let’s look at the design of the feature in detail.
In tapir, we already have a…
Time flies, and before you know it, we have another Java release. In line with the half-year release schedule, it’s time for Java 15, which paves the way for the upcoming Java 17 LTS (a year from now).
Java has seen a steady stream of improvements, many of them influenced by other JVM languages and functional programming. This includes features such as lambdas, limited local type inference or switch expressions. Scala is an especially rich source of ideas, due to its innovative object-oriented and functional programming blend.
Let’s take a look at how the (preview or final) features available in…
Recently at our semi-regular architecture discussion group, we’ve been looking at the Auth0 service: what it is, how it works and when it might be a good idea to use it.
I’d like to focus on the last aspect, using Auth0 as a case-study for the more general problem of when to use external services in our microservices mix, and when to roll your own.
On one hand, it’s totally reasonable not to write yet another
UserService which handles user authentication and authorization. It’s been done before, and we all like to reuse code. …
For the past three months we’ve been working on an update to sttp client, which is now available as version 3.0.0-RC4.
The main theme of the release is making sttp client simpler, safer and more developer-friendly.
More than ever, sttp client is THE Scala HTTP client you always wanted :)
There’s a couple of breaking changes — take a look at the release notes for the full overview. We’ll cover some of the new features below.
sttp client introduced web socket support in version 2. While the design was comprehensive, it was unnecessarily complex (too flexible!) and irregular. …