Anonymous method/delegate
If I want to use a function that takes two int
s and returns an int
as an argument for another function I need to create a delegate that I have to name:
delegate int MyDelegate(int x, int y);
void foo(MyDelegate d) {
stdout.printf("%d\n", d(3, 4));
}
void main() {
foo((x, y) => x + y);
}
It would be nice if the type MyDelegate
could be written without giving it a name. Something like
void foo(Func<int, int, int> d) {
stdout.printf("%d\n", d(3, 4));
}
void main() {
foo((x, y) => x + y);
}
I don't know C# but apparently this syntax works in C#.
This is probably the only syntax feature that I'm missing in Vala and it would make Vala less verbose when programming in a functional style.