# scalafp

## 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

Reading Time: 4 minutes It’s surprisingly hard to find a consistent definition of functional programming. But I think you can define FP with just two statements: 1. FP is about writing software applications using only pure functions. 2. When writing FP code you only use immutable values. Hence, Functional programming is a way of writing software applications using only pure functions and immutable values. Now, let us understand the Continue Reading

## Back2Basics: Understanding Partially Applied Functions

Reading Time: 3 minutes In this blog, we are going to talk about Partially applied functions and its use case. Before starting, first, we will emphasize that though Partial functions and Partially applied functions sound similar they are different from each other. To understand Partial Functions refer. What is function application? Applying a function is called calling a function. When we pass all arguments of the function, we can Continue Reading

## ScalaFP: Firsthand With Scala-Cats Monads – #1

Reading Time: 4 minutes In the previous post, we had a look at the reasons behind the monads and how monads can help us design the programs in a functional style. Now we are going to explore some of the monads which are frequently used in the applications but not available within the Scala predefined libraries. We will be exploring the monads which are provided by the scala-cats functional Continue Reading

## ScalaFP: Let’s Find The Reasons Behind Monads.

Reading Time: 5 minutes Monads in Functional Programming play an important role but they mostly confuse the beginners. One of the reasons for the confusion is that they mostly have a knowledge of imperative style programming, where they have no idea about function composition and its importance. In the terms of functional programming, the composition is the root where we have a set(Z) and we compose the elements of Continue Reading

## Back2Basics: Exception Handling – #3

Reading Time: 2 minutes In our previous blog Exception Handling – #2, we talked about how we can handle exception using Either. In this blog, we will explore further about Either, how we can elegantly handle exceptions using Either while working with Collections. We use collections when we want to perform some operations on elements. But what if something goes wrong while performing the transformation, do you have any 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: Exception Handling – #2

Reading Time: 3 minutes In our previous blog, we have seen how we can handle exceptions using try/catch and Try block.  In this blog, we will explore how we can handle exceptions using Either. Either, just like a Try, is also a container type which can have one value either Left or Right at a time. We can also use Option to handle exceptions but if an exception occurs returning Continue Reading

## Back2Basics: Exception Handling – #1

Reading Time: 3 minutes While building an application, it is common that something might go wrong. What if there is an attempt to divide a number by 0 or fetching the data from the database which does not exist, or reading a file which can’t be located? We need to handle such situations to make sure our application does not go down. Every language provides ways to handle such Continue Reading

## Back2Basics: Catalogue #2

Reading Time: 2 minutes Knoldus Inc is pleased to announce the launch of “Back2Basics: Tutorials”. We at Knoldus firmly believe that quality of coding plays an important role in the success of any IT organization and here we are adding a few more steps to heighten out coding benchmarks. At Knoldus we are laying the foundation for adopting healthier scala coding environment through getting and setting our Basics right. In our 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

## Back2Basics: The Magic of Implicit – #2

Reading Time: 3 minutes In our previous blog, The Magic of Implicit, we have talked about how implicit values are being used. In this blog, we will explore Type Conversion with implicit and implicit classes. Let’s start with a simple example, scala> val i: Int = 2.3 <console>:11: error: type mismatch; found : Double(2.3) required: Int val i: Int = 2.3 Here we were trying to assign a double type value Continue Reading

## ScalaFP: Mystery Of Scala Higher Kinded Type.

Reading Time: 3 minutes Scala type system holds a lot of mysteries. Sometimes these mysteries confuse us but mostly they provide us with a powerful feature. Today we will be discussing one of them called Higher Kinded Type Or Second Order Type. Before moving to higher kinded type lets brush up our basics first. Higher Order Function: So, functional programming follows an artistic rule called “functions are the first Continue Reading