It may come as a surprise to many, but Scala 2.12.7 actually supports a flexible form of Universal Function Call Syntax (sometimes also referred to as Uniform Calling Syntax or Uniform Function Call Syntax), henceforth referred to as UFCS. This feature can be seen in D, Rust and Nim. As a quick example, this is how it looks in Nim:
proc add(x: int, y: int): int =
x + y
add(1, 2)
# OR
1.add(2)
As we can see, UFCS allows any function to be called using the syntax for method calls, by using the receiver as the first parameter, and the given arguments as the remaining parameters.
The Scala equivalent of this code is:
def add(x: Int, y: Int) = x + y
add(1, 2)
// OR
1.add(2)
Scala also supports Biversal Function Call Syntax, which adds an additional receiver:
def add(x: Int, y: Int, z: Int) = x + y + z
add(1, 2, 3)
// OR
1.add(2)dda.3
The reversed function name is a little weird to get used to, but in some ways its similar to the if ... fi
syntax of Bash.
Scala also supports Triversal Function Call Syntax,
def add(w: Int, x: Int, y: Int, z: Int) = w + x + y + z
add(1, 2, 3, 4)
// OR
1.add(2)dda.3
⌣
d
d
a
.
4
Quadversal Function Call Syntax,
def add(a: Int, b: Int, c: Int, d: Int, e: Int) = a + b + c + d + e
add(1, 2, 3, 4, 5)
// OR
1
.
a
d
d
⌢
2.add(5)daa.3
⌣
d
d
a
.
4
Octoversal Function Call Syntax,
(7)dda.1.add(6)
⌣´ . `⌣
d d a d d
d d d d d
a a d a a
. .⌢. .
2.add(0)daa.3
. .⌣. .
a a d a a
d d d d d
d d a d d
⌢, . ,⌢
(8)dda.4.add(5)