Know About Partial Functions in Scala under 3 Minutes

Reading Time: 3 minutes Functions and methods are essential components of programming. They help us to process input and provide us with output. In this blog, we will learn about partial functions through examples in Scala. Note: Do not confuse it with partially defined functions. What are partial functions? In English, “partial” means something which is not complete. Similarly, a partial function is a function applicable only for a Continue Reading

Scala Extractors

The Scala Chronicles: PartialFunction

Reading Time: 3 minutes If you’re new to programming in Scala(like I am), you must have heard someone or the other talking about how awesome and powerful the case keyword, Partialfunction and pattern matching in Scala are. It got me wondering about why people love them that much. So, to unravel this mystery around case, I went on an adventure to find out all there is to know about them(And Continue Reading


Back2Basics: Understanding Partial Function – #2

Reading Time: 3 minutes In previous blog Understanding Partial Functions – #1, we have talked about what is partial function and how they are different from regular functions. In this blog, we will explore more about the partial function. We have talked about how we can define partial functions having one argument. But what to do if we have to pass more than one argument. Let’s try defining divide Continue Reading


Back2Basics: Understanding Partial Functions – #1

Reading Time: 3 minutes   In this blog, we will talk about partial functions. We know about functions in Scala. Let’s talk about it first. So, what is a function? A function is a mapping or a transformation of an input to an output. For example,  we have function isEven, which takes an int value and retuns boolean value. scala> def isEven(x :Int) = x % 2 == 0 Continue Reading

Partial Functions and Modularizing Actor Receive blocks

Reading Time: 2 minutes A partial function is defined as trait PartialFunction[-A, +B] extends (A) ⇒ B It is a unary function which defines a domain. Not all values of A would be a part of the domain. For instance, in the following code block val sample = 1 to 10 val isEven: PartialFunction[Int, String] = { case x if x % 2 == 0 => x+" is even" Continue Reading