1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Lambda return type inference

This commit is contained in:
Brian Fiete 2021-01-14 06:24:34 -08:00
parent d557e11dad
commit bb12a4ec20
6 changed files with 220 additions and 41 deletions

View file

@ -241,6 +241,17 @@ namespace Tests
return 0;
}
public static TResult Sum<T, TElem, TDlg, TResult>(this T it, TDlg dlg)
where T: concrete, IEnumerable<TElem>
where TDlg: delegate TResult(TElem)
where TResult: operator TResult + TResult
{
var result = default(TResult);
for(var elem in it)
result += dlg(elem);
return result;
}
[Test]
public static void TestBasics()
{
@ -293,6 +304,8 @@ namespace Tests
} == false);*/
Test.Assert(MethodE(floatList) == 6);
Test.Assert(MethodF(floatList) == 0);
Test.Assert(floatList.Sum((x) => x * 2) == 12);
}
}