Archive: October 2019

Functional dependency injection in Scala using ZIO environments

Posted on by  
Chiel van de Steeg

ZIO is a type-safe, composable library for asynchronous and concurrent programming in Scala (from: The ZIO github). The library copes with functional IO, like many Functional Programming libraries do. The added value of ZIO is that the ZIO[R, E, A] type-constructor (the main IO monad of the library) acts as an IO monad, an error handling monad, and a reader monad. A functional programming style often needs a combination of these three types to cope with the most common problems when creating an application:

  • performing side effects (getting the A)

  • coping with errors (handling E)

  • supplying dependencies (providing R)

This blogpost will show you how to cope with the R part of a ZIO[R, E, A]: the Environment

Continue reading →

Spring Security: Custom Permission Evaluator

Posted on by  
Tim te Beek

Often you’ll find access decisions move beyond simplistic ownership or having a certain role, for instance when users share domain objects with other users. In such cases it’s common to separate permission to view an instance from being able to make changes to the same instance. When your access rules are relatively straightforward, Spring Security offers the PermissionEvaluator interface to secure instance access.

Continue reading →

Distributed Tracing with Kafka Streams

Posted on by  
Tim te Beek

Distributed tracing is a method used to profile and monitor applications, especially those built using a microservices architecture. Distributed tracing helps pinpoint where failures occur and what causes poor performance.[1] Applied to Kafka Streams it allows us to trace and visualize our messages by propagating diagnostic information within message headers.

Continue reading →

Don't pass null to a function

Posted on by  
Ties van de Ven

I have seen the following pattern appear quite a lot:

private String foo(String bar) {
  if(bar != null){
    return "bar";
  }
  return null;
}

Here the function is called with a nullable argument, and if the argument was null, the function will return null, and if not it will return a proper value. I do not like this, and here is why.

Continue reading →

Converting Char to Int in Kotlin

Posted on by  
Riccardo Lippolis

The Kotlin standard library contains a lot of helper functions on top of the Java standard library for our convenience. Some of those functions help us in converting between different data types. For example, the String.toInt() function converts a number formatted as String to its Int representation. But how do we accomplish the same with a Char? Spoiler alert: NOT by using Char.toInt(), but by using Char.digitToInt()!

Continue reading →

Kotlin method reference to companion object function

Posted on by  
Riccardo Lippolis

Functions defined in Kotlin companion objects are often seen as the 'equivalent' of static methods in Java. Although there are some similarities, there are also some caveats you should be aware of. For example, how to use method references (or, to be pedantic: function references) to refer to functions defined in a companion object.

Continue reading →

Customising form validation in Javalin using Valiktor

Posted on by  
Justus Brugman

Since about a month I’m developing some microservices using Javalin, a small, simple and lightweight web-framework that started as a fork from SparkJava. By now it’s a ground-up rewrite, influenced by the Javascript framework koa.js. Don’t let the stuff like Either scare you, we use the Arrow library to make our life a bit more easy :)

When requesting user input from a form, it’s evident that we need to validate our input. Javalin has its own way of doing so (from the docs):

Continue reading →

shadow-left