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.
Scala 3 aka dotty comes with a lot of new types. Union, Intersection , Opaque etc. Let’s understand union and intersection types in detail.
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.
…
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. …
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…
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. …
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. …
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 https://github.com/ayushworks/pariksha
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
case…
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.
We defined a Lock and a Key class. You need a key to open a lock. Looks neat! Lets use it..