Image for post
Image for post
Photo by Ben Hershey on Unsplash

Scala 3 has an optional feature which changes the Type hierarchy when enabled. Its called “Explicit Nulls” and when enabled via the flag -Yexplicit-nulls the language has a different way of working with null values.

“Null” in current scala hierarchy

Image for post
Image for post
Photo by Denys Nevozhai on Unsplash

Scala 3 aka dotty comes with a lot of new types. Union, Intersection , Opaque etc. Let’s understand union and intersection types in detail.

Union types

A union type A | B represents a type that has values of type A or B at a given time. A pattern match must be performed at the point of usage to extract the exact type.

This would not have been possible in Scala 2. We would have to create a super type for our types and then create the method with the super type.

Rules for Union types

  • Union types are commutative i.e

Scala 3 aka Dotty has been a topic of discussion in Scala community for almost 4 years now. The announcement of Scala 3.0.0-M3 release is a big milestone in this journey and paves way for a RC1, which is tentatively planned for January 2021.

There are lots of new features and improvements in Scala 3. Martin Odersky’s talk is a must for anyone looking for a sneak peek into the language’s future. …

Image for post
Image for post
Photo by Fabrizio Conti on Unsplash

Observability helps us understand the internals of a software from outside. Every enterprise software which is scalable and resilient to new changes needs to built using the principle of observability. A high quality software with no bugs, eventually with growing usage and complexity will present unknown problems. That is the hard truth we must accept. We should recognise what the SRE model emphasises: systems will continue failing. Observability will help us in understanding those failures better.

Logs, metrics, and traces are often regarded as the three pillars of observability. People might disagree on relative importance of each of these, but…

Image for post
Image for post
Photo by Sanjeevan SatheesKumar on Unsplash

This is a write up about how to design applications that maintain shared state, use concurrent code and are still based on the principles of functional programming. But first lets understand why it is easier said than done

The trouble is that essentially all the interesting applications of concurrency involve the deliberate and controlled mutation of shared state, such as screen real estate, the file system, or the internal data structures of the program. The right solution, therefore, is to provide mechanisms which allow the safe mutation of shared state section.

— Peyton Jones, Andrew Gordon, and Sigbjorn Finne in…

This post is an attempt to explain a “Kleisli” category in as simple way as possible. Many before have tried and some have succeeded.

A category consists of objects and arrows that go between them. These arrows compose such that if there is an arrow from A to B and another arrow from B to C, then there must be an arrow from A to C.

This is category theory 101. In Scala these objects are represented by types and the arrows are functions that are defined in these types. …

Image for post
Image for post
Photo by Ksenia Kudelkina on Unsplash

Rate limiting is a common feature that come across these days. With the upsurge of cloud based api’s , rate limiting has become a de-facto standard of protecting the resources and controlling requests.

What is rate limiting ?

Rate limiting is used to control the amount of incoming and outgoing traffic to or from a network. For example, let’s say you are using a particular service’s API that is configured to allow 100 requests/minute. If the number of requests you make exceeds that limit, then an error will be triggered. …

Image for post
Image for post

Recently i started working on a library that does validation on scala types.

The original aim was to write a library that was could be used for data validation on incoming api requests in a web application . Then i saw some other scala validation libraries like Accord and octopus and i thought to extend the ideas expressed there. The source code for Pariksha (which means test in Hindi) can be found at

The protagonist of our story is the Validator[T] trait which validates instances of T by using a list of Validation[T].

Consider a simple case class


Variance in Scala is an aspect related to parameterized types. The use of variance in the type system allows us to make intuitive connections between complex types, whereas the lack of variance can restrict the reuse of a class abstraction. We start with an example to understand the theory. Lets define a bag that can be full or empty

There is only possible Empty bag whose contents are Nothing and hence it modeled by a case object. A Full bag can be filled with different contents. We now create contents and pack our bag.

Lets now try packing…

There is no better way to understand path dependent types and their importance in Scala other than by directly looking at the problem that they help us solve.

Let us implement a very simple Lock/Key using Scala.

Image for post
Image for post
A simple lock and key

We defined a Lock and a Key class. You need a key to open a lock. Looks neat! Lets use it..

ayush mittal

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store