Hexagonal vs Layers Architecture
If you are familiar with the layers architectural pattern, it is only a small step to the even nicer hexagonal pattern. Here is an example of how you can do it.
If you are familiar with the layers architectural pattern, it is only a small step to the even nicer hexagonal pattern. Here is an example of how you can do it.
A Software Bill of Materials (SBOM) is a broad inventory of all components, libraries, and other third-party assets used in a software application. It’s a detailed list of all the components that go into the software, much like a recipe lists the ingredients needed to prepare a dish.
We’ll compare some code written with Either with similar code written using Exceptions and see how they are the same and how they differ.
WireMock is a stub framework that helps you create stubs for outgoing HTTP traffic during your tests. Most people use WireMock in their test suite during build time of the application. Spin up the WireMock server, configure some stub rules, run the application tests, and tear everything down. This is a good way of testing your HTTP clients, using real traffic towards an external server.
The chunked
extension method is added to the Iterable
Java class and makes it possible to split an interable into fixed sized lists. We define the size of the lists as argument to the chunked
method. The return result is a list of lists. Each of the lists will have the number of elements we have specified as argument. The last list can have less elements if the total number of elements cannot be divided exactly by the size we specified as argument. We can specify a lambda transformation function as second argument. The lambda function has the new sublist as argument and we can write code to transform that sublist.
The method partition
is available in Kotlin for arrays and iterable objects to split it into two lists. We pass a predicate lambda function to the partition
method. The predicate should return either true
or false
based on a condition for each element from the array or iterable. The return result is a Pair
instance where the first element is a List
object with all elements that returned true
from the predicate. The second element in the Pair
object contains all elements for which the predicate returned false
. As a String
can be seen as an iterable of characters we can also use partition
on a String
instance.
Developer experience, or DX for short, describes the overall feelings and perceptions a developer has while interacting with a language, tool or technique. The easier it is for a developer to work with the language, tool or technique the higher their sense of DX is. In this blog, I will briefly touch on DX but will also focus on experience in a broader meaning within software engineering.
Kotlin adds a lot of extension methods to the String
class. For example we can use the take
method to get a certain number of characters from the start of a string value. With the drop
method where we remove a given number of characters from the start of the string to get a new string. We can also take and drop a certain number of characters from the end of a string using the methods takeLast
and dropLast
.
Instead of using the number of characters we want to take or drop we can also use a condition defined with a predicate lambda function. We take or drop characters as long as the lambda returns true
. The names of the methods for taking characters are takeWhile
and takeLastWhile
and for dropping characters dropWhile
and dropLastWhile
.
If we want to find the longest shared prefix or suffix for two string values we can use the String
extension methods commonPrefixWith
and commonSuffixWith
. The result is the prefix or suffix value that is common for both values. We can pass a second argument to the method to indicate if we want to ignore the casing of the letters. The default value for this argument is false
, so if we don’t set it explicitly the casing of the letters should also match.
Kotlin gives us the associate
method for collection objects, like lists, iterables and arrays. With this method we can convert the items in the collection to a new Map
instance. The associate
method accepts a lambda function as argument and we must return a Pair
from the lambda. The first item of the pair will be the key and the second element is the value of the key/value pair in the resulting map.
If we want to use the elements in our collection as key, but want to transform the value we must use associateWith
. The lambda for this method must return the value part of our key/value pair. Alternatively if we only want to transform the key value we can use associateBy
with one lambda function. The lambda function must return the result for the key in the key/value pair of the map. The method associateBy
is overloaded where we can pass two lambda functions. The first lambda function is for transforming the key and the second lambda function is for transforming the value.