Uniform function call syntax
Appearance
Uniform Function Call Syntax (UFCS) is a programming language feature in D that allows any function to be called on an object (as in Object-oriented programming) like the function is a method of its class.[1] UFCS is particularly useful when function calls are chained.[2]
Examples
import std.stdio;
int first(int[] arr)
{
return arr[0];
}
int[] addone(int[] arr)
{
int[] result;
foreach (value; arr) {
result ~= value + 1;
}
return result;
}
void main()
{
auto a = [0, 1, 2, 3];
// All the followings are correct and equivalent
int b = first(a);
int c = a.first();
int d = a.first;
// Chaining
int[] e = a.addone().addone();
}