Scala Curried or currying functions

 253 total views,  1 views today

Welcome to Scala series. In this tutorial, you will learn about Scala Curried or currying functions in detail.

Usually a method or a function can have N number of arguments.


def add(a: Int, b: Int): Int = {
    a + b


Result : 4

The above function/method has two arguments a and b.

Curried or Currying functions

In Scala, a method/function can also have multiple parameters list which called as currying functions or curried functions.

def add(x: Int) = (y: Int) => {
    x + y

The above function/method accepts two list of arguments x and y. The method should be invoked as below.


Result : 4

Curried or Currying functions examples

def add2(x: Int) = (y: Int) => (z: Int) => (a: Int) => {
    x + y + z + a


Result : 10


def add3(x: Int) = (y: Int, z: Int) => (a: Int) => (b: Int) => {
    x + y + z + a + b


Result : 15

References : Scala Curried or currying functions documentation

I hope you like this mini tutorial and you were able to understand how Curried or currying functions works.

Thanks for reading and please give us a thumb up and comment below!

Tags :

About the Author


Hey There, My name is Rajasekar and I am the author of this site. I hope you are liking my tutorials and references. Programming and learning new technologies are my passion. The ultimate idea of this site is to share my knowledge(I am still a learner :)) and help you out!. Please spread your words about us ( and give a thumbs up :) Feel free to contact me for any queries!.