This code:
import std.algorithm : each;
void main()
{
auto arr = [1,2,3];
arr.each!(x => writeln(x));
}
won't compile:
/d768/f609.d(8): Error: template f609.main.each!((x) => writeln(x)).each cannot deduce function from argument types !()(int[]), candidates are:
/opt/compilers/dmd2/include/std/algorithm/iteration.d(875): f609.main.each!((x) => writeln(x)).each(Range)(Range r) if (isRangeIterable!Range && !isForeachIterable!Range)
/opt/compilers/dmd2/include/std/algorithm/iteration.d(899): f609.main.each!((x) => writeln(x)).each(Iterable)(Iterable r) if (isForeachIterable!Iterable)
The real problem is that x => writeln(x) doesn't compile because you missed import std.stdio in this case. The same goes if any error exists inside lambda. But error won't give help you that much (in this case error is easy to spot)
Comment #1 by robert.schadek — 2024-12-01T16:26:27Z