Service Symphony

Currying Scala Vs Java

A quick contrast of currying using Java 8 and Scala.

Java 8

private static Function<Integer, Function<Integer, Integer>> add() {
return x -> y -> x + y;
}
Function<Integer, Integer> add1 = add().apply(1);
int r = add1.apply(2)

Scala

val add1 = add(1)(_)
val r = add1(2)
def add(x : Int)(y : Int) = x + y

Alternatively,

val add1 = add(1)
val r = add1(2)
def add(x : Int) = (y : Int) => x + y

Share this:

One response to “Currying Scala Vs Java”

  1. Lurraine says:

    I cannot tell a lie, that really hedple.

Leave a Reply

Your email address will not be published. Required fields are marked *

four × three =

Some of our
Clients
Service Symphony

Service symphony © 2023

Quick Links
Contact Info

20-22 Wenlock Road
London
N1 7GU
United Kingdom

Support

0800 011 4386