-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinqImplementation.cs
43 lines (40 loc) · 1.16 KB
/
LinqImplementation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
namespace linq;
public static class IEnumerableExtension
{
public static IEnumerable<T> NewWhere<T>(this IEnumerable<T> items, Func<T, bool> predicate)
{
foreach (var item in items)
{
if (predicate(item))
{
yield return item;
}
}
}
public static IEnumerable<TResult> NewSelect<T, TResult>(this IEnumerable<T> items, Func<T, TResult> selector)
{
foreach (var item in items)
{
yield return selector(item);
}
}
public static IEnumerable<TResult> NewJoin<T, Tinner, TKey, TResult>(
this IEnumerable<T> items,
IEnumerable<Tinner> innerItems,
Func<T, TKey> outerKeySelector,
Func<Tinner, TKey> innerKeySelector,
Func<T, Tinner, TResult> resultSelector
)
{
foreach (var item in items)
{
foreach (var innerItem in innerItems)
{
if (outerKeySelector(item).Equals(innerKeySelector(innerItem)))
{
yield return resultSelector(item, innerItem);
}
}
}
}
}