What Is a Monad? Basic Theory for a Java Developer

As you can guess from the title, the main topic of this article will be monads. I will try to dive deep in their structure and inner workings. With some help of Java Optional, I will try to describe all of this in a more detailed way. At the end of this article, I will implement a log monad — a type of a writer monad —and then describe the role of each major code fragment and provide a simple example of its usage.

Why Learn How Monads Work?

First of all, it is always good to have a basic understanding of how things that we use work. If you are a Java developer, you probably use monads without even knowing about it. It may surprise you, but two of the most commonly known Java 8 features are monad implementations, namely Stream and Optional. In addition, functional programming becomes more and more popular nowadays so it is possible that we will have more similar monadic structures. Then, this knowledge will be even more very valuable.

Let’s start with describing what a monad is – more or less accurately. In my opinion, the matter here is fairly straightforward.

Optional.orElse() Vs. Optional.orElseGet()

Learn more about programming Java Optionals

A very common misunderstanding, as well as bad usage, can prevail if you simply go by the dictionary and semantic definition of Optional.orElse() and Optional.orElseGet().

A smart man makes a mistake, learns from it, and never makes that mistake again. But a wise man finds a smart man and learns from him and how to avoid the mistake altogether.

All Things Java 8 [Tutorials]

Java 8
No matter what version of the JDK we are on, Java 8 is not going anywhere.

Java 8 introduced a new era of Java. Everything from lambda expressions and functional programming to Streams and collections — DZone was there to document it all.

So whether you're migrating over to Java 9 or Java 11, or maybe even Java 13, Java 8 concepts and features are still very much alive in the JDK. And understanding these core concepts can help tremendously when it's time to move beyond Java 8.

Folding Things With Functional Programming

Folding things can be fun!

Introduction

In this post, we will discuss the concept of fold in functional programming: fold functions are used to reduce a data structure containing multiple values into a single one. Associated to the idea of fold are the concepts of...

  • recursion: via recursion, fold traverses the different elements of the data structure.
  • summarisation: the data structure with all its elements is reduced to a single value
You may also like: 10 Amazing Scala Collection Functions

In the following example, the class Rectangle can be reduced to a single value representing its area. However, it is not 'foldable' in the sense that there is no recursion involved.

The Role of Erlang in Programming Blockchains

With the advent of blockchain technology, we’re witnessing an explosion of interest in bringing to life the decentralized applications of the future. Some of the best-known programming languages used in the development of blockchain platforms are object-oriented languages. Languages such as C++, Python, and the purpose-built Solidity have so far dominated the blockchain scene.

Functional programming languages are quickly becoming a developer’s first choice when building Dapps, as they largely influence what can and can’t be done, and possess unique features that help them exhibit important comparative advantages.

Functional Programming in Spring MVC

Spring 5.0 embraced the ReactiveStreams specification and introduced a new Reactive Stack as an alternative to the traditional Servlet stack. And, it also brought a new functional programming model to developers, but it is only supported in the Reactive Stack.

The good news is that, in the coming 5.2, the functional-like APIs are being ported back to the Servlet stack. For those developers who are stuck on Servlet stack and want to experience the new programming model, it is absolutely startling news.

Immutable Data With FunctionalJ.io

Immutability is an important principle of functional programming. Mutable objects hide changes. And hidden changes can lead to unpredictability and chaos.

FunctionalJ provides ways to create and manipulate immutable data. In this article, I discuss @Struct, which generates custom immutable classes. On the surface, it is very similar in concept with Lombok's @Value. However, FunctionalJ's @Struct comes with its own unique features, such as: