0Pricing
Scala for Backend Engineering & Functional Programming · Lesson

Currying

Partial application.

Currying is a free Scala for Backend Engineering & Functional Programming lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Scala for Backend Engineering & Functional Programming learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What is currying?

Currying transforms a function of several arguments into a chain of functions, each taking one argument. In Scala this is written with multiple parameter lists.

object Main {
  def add(a: Int)(b: Int): Int = a + b
  def main(args: Array[String]): Unit = {
    println(add(3)(4))
  }
}

Multiple parameter lists

A curried method has several parameter lists: def f(a: Int)(b: Int). You call it by supplying each list in turn: f(1)(2).

object Main {
  def combine(prefix: String)(value: Int): String = s"$prefix$value"
  def main(args: Array[String]): Unit = {
    println(combine("id-")(42))
  }
}

Partial application

You can apply only some argument lists and get back a function awaiting the rest. This is called partial application.

object Main {
  def add(a: Int)(b: Int): Int = a + b
  def main(args: Array[String]): Unit = {
    val addFive = add(5) _
    println(addFive(10))
    println(addFive(20))
  }
}

Specializing a general function

Partial application lets you build specialized functions from a general one, reducing repetition.

object Main {
  def power(exp: Int)(base: Int): Int = math.pow(base, exp).toInt
  def main(args: Array[String]): Unit = {
    val square = power(2) _
    val cube = power(3) _
    println(square(5))
    println(cube(2))
  }
}

Currying a normal function

An ordinary function value has a .curried method that converts it into curried form.

object Main {
  def main(args: Array[String]): Unit = {
    val add = (a: Int, b: Int) => a + b
    val curriedAdd = add.curried
    println(curriedAdd(3)(4))
  }
}

Uncurrying back

The Function.uncurried helper reverses the process, turning a curried function back into one with a single parameter list.

object Main {
  def main(args: Array[String]): Unit = {
    val curried: Int => Int => Int = a => b => a + b
    val normal = Function.uncurried(curried)
    println(normal(3, 4))
  }
}

Why currying is useful

Currying enables reuse: fix the first arguments once, then call the result many times with different remaining arguments. It also helps the compiler infer types in later lists.

object Main {
  def discount(rate: Double)(price: Double): Double = price * (1 - rate)
  def main(args: Array[String]): Unit = {
    val blackFriday = discount(0.3) _
    println(blackFriday(100))
    println(blackFriday(250))
  }
}

Type inference in the last list

A practical reason for multiple parameter lists: the compiler can infer the lambda's parameter types from earlier lists, so you can omit them.

object Main {
  def fold[A](xs: List[A])(init: A)(op: (A, A) => A): A =
    xs.foldLeft(init)(op)
  def main(args: Array[String]): Unit = {
    val total = fold(List(1, 2, 3))(0)((a, b) => a + b)
    println(total)
  }
}

Currying with three lists

You can have as many parameter lists as you like. Each call supplies one list and returns a function for the next.

object Main {
  def make(a: Int)(b: Int)(c: Int): Int = a + b + c
  def main(args: Array[String]): Unit = {
    println(make(1)(2)(3))
    val step = make(10) _
    println(step(20)(30))
  }
}

Building configurable validators

A common real use: curry a validation rule, fix the threshold, and reuse the resulting predicate across a dataset.

object Main {
  def atLeast(min: Int)(value: Int): Boolean = value >= min
  def main(args: Array[String]): Unit = {
    val adult = atLeast(18) _
    println(List(15, 21, 18, 12).map(adult))
  }
}

Currying vs partial application

Currying is the structural transformation into one-argument functions. Partial application is the act of supplying some arguments now and the rest later. Curried functions make partial application natural.

object Main {
  def greet(greeting: String)(name: String): String = s"$greeting, $name!"
  def main(args: Array[String]): Unit = {
    val sayHi = greet("Hi") _
    println(sayHi("Ann"))
    println(sayHi("Bob"))
  }
}

Quick Check

How do you define a curried method in Scala?

Recap

You learned currying and partial application:

  • Curried methods use multiple parameter lists: f(a)(b)
  • Partially apply with f(x) _ to get a new function
  • .curried and Function.uncurried convert forms
  • Helps reuse, specialization, and type inference

Frequently asked questions

Is the “Currying” lesson free?

Yes — the full text of “Currying” is free to read here on the web, and the Scala for Backend Engineering & Functional Programming course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Scala for Backend Engineering & Functional Programming course, upgrade to CoddyKit PRO.

What will I learn in “Currying”?

Partial application. You practise Scala for Backend Engineering & Functional Programming with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Scala for Backend Engineering & Functional Programming?

No prior experience is required. Scala for Backend Engineering & Functional Programming on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Currying” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Scala for Backend Engineering & Functional Programming lesson?

Yes. Every Scala for Backend Engineering & Functional Programming lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Functions as Values
  2. Currying
  3. Composition
  4. Closures
← Back to Scala for Backend Engineering & Functional Programming