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:
parent
d557e11dad
commit
bb12a4ec20
6 changed files with 220 additions and 41 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue