-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathDelegateExtensions.cs
More file actions
21 lines (17 loc) · 1021 Bytes
/
DelegateExtensions.cs
File metadata and controls
21 lines (17 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
using System.Threading;
using System.Threading.Tasks;
namespace NetFabric.Hyperlinq
{
static class DelegateExtensions
{
public static Func<TSource, CancellationToken, ValueTask<bool>> AsAsync<TSource>(this Func<TSource, bool> predicate)
=> (item, _) => new ValueTask<bool>(predicate(item));
public static Func<TSource, int, CancellationToken, ValueTask<bool>> AsAsync<TSource>(this Func<TSource, int, bool> predicate)
=> (item, index, _) => new ValueTask<bool>(predicate(item, index));
public static Func<TSource, CancellationToken, ValueTask<TResult>> AsAsync<TSource, TResult>(this Func<TSource, TResult> selector)
=> (item, _) => new ValueTask<TResult>(selector(item));
public static Func<TSource, int, CancellationToken, ValueTask<TResult>> AsAsync<TSource, TResult>(this Func<TSource, int, TResult> selector)
=> (item, index, _) => new ValueTask<TResult>(selector(item, index));
}
}