If you’re new to the concept of type classes I suggest you read my other article explaining them. The Cats library makes extensive use of type classes and a basic understanding is a prerequisite for this article.
In previous articles, we talked about Semigroups and Monoids, which are abstractions that let us combine values of the same type together.
In this post, we’ll take a look at Functors, which allow us to operate on values inside containers without having to know any of the implementation details of the containers themselves.
In terms of functional programming, a Functor is simply something…
Today we are going to deep dive into the Scala Cats again to find out about Monoids. If you haven’t already read my post about Diving into Scala Cats — Semigroups I suggest you do so now.
The Monoid extends Semigroup and adds a default or fallback value for the given type. Monoid
type class comes with two methods - one is the combine
method of Semigroups, and another one is the empty
method that performs identity operation.
In the post about Semigroups, we saw an example where we’re using Semigroups along with Scala’s fold()
to operate on a collection…
New to Cats? No worries, go through my previous article Getting Started with Scala Cats to understand how amazing Cats is.
In this article, we will cover the concepts and implementation of Semigroups in Cats.
In functional programming terms a Semigroup is a concept which encapsulates aggregation with an associative binary operation.
The Semigroup type class comes with a method combine
which simply combines two values of same data type by following the principle of Associativity.
combine
method is constructed as:
trait Semigroup[A] {
def combine(x: A, y: A): A
}
and can be implemented as:
// The type class…
This article is about Scala Cats. It is a library that provides the abstraction for functional programming in the Scala programming language. The name is a playful shortening of the word category.
Cats is a lightweight, modular, and extensible library for functional programming.
Cats contains a wide variety of functional programming tools and allows developers to pick the required ones. The majority of these tools are delivered in the form of type classes that we can apply to existing Scala types.
Type classes are a programming pattern originating in Haskell. They allow us to extend existing libraries with new functionality…
This blog was first published on Knoldus Blogs
This series is all about the taste of Scala.
It is best suitable for all the newbies in Scala.You may also like:
Scala Beginner Series (1) : Basics
Scala Beginner Series (2) : Object Oriented Scala
In the previous part, we covered the:
This article will cover the functional nature of the Scala language.
The first fundamental concept of functional Scala is pure functions.
Here is a very strict definition of…
This blog was first published on Knoldus Blogs
According to the Reactive Manifesto, a critical element in any Reactive system is that it is message-driven. But what does it mean to be message-driven?
Message-driven systems are those that communicate primarily through asynchronous and non-blocking messages. Messages enable us to build systems that are both resilient, and elastic, and therefore responsive under a variety of situations.
We have various ways of accomplishing synchronous and asynchronous messaging. But when we try to use synchronous messages to accomplish the task where an asynchronous message is required or vice-versa, things break down. …
This blog was first published on Knoldus Blogs
This series is all about the taste of Scala.
It is best suitable for all the newbies in Scala.You may also like: Scala Beginner Series (1) : Basics
In the previous part, we covered:
This article will cover the object oriented nature of Scala language.
Scala has the same concept of a class as we have in other languages.
Classes in Scala are blueprints for creating objects. They can contain methods, values, variables, objects, traits and super-classes which are collectively…
This blog was first published on Knoldus Blogs
This series is all about the taste of Scala. It is best suitable for all the newbies in Scala. So here we go…
This article will cover the fundamentals of Scala language.
In Scala, we work with values:
Values are used to define constants. val
modifier means constant or immutable that means we cannot change its value once it is created. Thus reassignment to val
is prohibited.
This blog was first published on Knoldus Blogs
Building a Reactive System is all about the balance between consistency and availability and the consequences of picking one over the other. This article mainly focuses on consistency and availability and how they impact the scalability of a system.
What is Scalability, Consistency and Availability?
A system is considered scalable if it can meet the increase in demand while remaining responsive.
A system is considered consistent if all the nodes show the same data at the same time.
A system is considered available if it remains responsive despite any failures.
How does…
This blog was first published on Knoldus Blogs
In this article, we will cover the transition from Monoliths to Service Oriented Architecture to Reactive Microservices by applying isolation techniques to the application.
To start explaining the microservices it’s useful to compare it to the monolithic application. An application is said to be a monolith when it is deployed as a single unit. Monoliths have a single shared database. They communicate with synchronous method calls where you send a message and expect a response immediately.
Software Developer