Skip to content

Commit 856050e

Browse files
committed
Discard was merged, updated the pull request wit overloads for 2 and 3 parameters.
1 parent b735e84 commit 856050e

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using static Funcky.Discard;
2+
3+
namespace Funcky.Test.Extensions.FuncExtensions;
4+
5+
public class ApplyTest
6+
{
7+
[Fact]
8+
public void CanApplyParametersInAnyOrder()
9+
{
10+
var func = Linear0;
11+
12+
var f1 = ((Func<int, int, int, int>)Linear0).Apply(__, __, 10);
13+
var f2 = func.Apply(2, __, 7);
14+
var f3 = Funcky.Extensions.FuncExtensions.Apply<int, int, int, int>(Linear0, __, __, 42);
15+
16+
Assert.Equal(30, f1(10, 2));
17+
Assert.Equal(72, f2(10));
18+
Assert.Equal(30, f3(10, 2));
19+
}
20+
21+
[Fact]
22+
public void Test2()
23+
{
24+
}
25+
26+
private static int Linear0(int a, int b, int c)
27+
=> a + (b * c);
28+
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace Funcky.Extensions;
2+
3+
public static partial class FuncExtensions
4+
{
5+
// All overloads for Fuctions with 2 paramters.
6+
public static Func<T1, TResult> Apply<T1, T2, TResult>(this Func<T1, T2, TResult> function, Unit arg1, T2 arg2)
7+
=> (a1) => function(a1, arg2);
8+
9+
public static Func<T2, TResult> Apply<T1, T2, TResult>(this Func<T1, T2, TResult> function, T1 arg1, Unit arg2)
10+
=> (a2) => function(arg1, a2);
11+
12+
// All overloads for Fuctions with 3 paramters.
13+
public static Func<T2, T3, TResult> Apply<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> function, T1 arg1, Unit arg2, Unit arg3)
14+
=> (a2, a3) => function(arg1, a2, a3);
15+
16+
public static Func<T1, T3, TResult> Apply<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> function, Unit arg1, T2 arg2, Unit arg3)
17+
=> (a1, a3) => function(a1, arg2, a3);
18+
19+
public static Func<T1, T2, TResult> Apply<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> function, Unit arg1, Unit arg2, T3 arg3)
20+
=> (a1, a2) => function(a1, a2, arg3);
21+
22+
public static Func<T3, TResult> Apply<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> function, T1 arg1, T2 arg2, Unit arg3)
23+
=> a3 => function(arg1, arg2, a3);
24+
25+
public static Func<T2, TResult> Apply<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> function, T1 arg1, Unit arg2, T3 arg3)
26+
=> a2 => function(arg1, a2, arg3);
27+
28+
public static Func<T1, TResult> Apply<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> function, Unit arg1, T2 arg2, T3 arg3)
29+
=> a1 => function(a1, arg2, arg3);
30+
}

Funcky/PublicAPI.Unshipped.txt

+8
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
#nullable enable
2+
static Funcky.Extensions.FuncExtensions.Apply<T1, T2, T3, TResult>(this System.Func<T1, T2, T3, TResult>! function, Funcky.Unit arg1, Funcky.Unit arg2, T3 arg3) -> System.Func<T1, T2, TResult>!
3+
static Funcky.Extensions.FuncExtensions.Apply<T1, T2, T3, TResult>(this System.Func<T1, T2, T3, TResult>! function, Funcky.Unit arg1, T2 arg2, Funcky.Unit arg3) -> System.Func<T1, T3, TResult>!
4+
static Funcky.Extensions.FuncExtensions.Apply<T1, T2, T3, TResult>(this System.Func<T1, T2, T3, TResult>! function, Funcky.Unit arg1, T2 arg2, T3 arg3) -> System.Func<T1, TResult>!
5+
static Funcky.Extensions.FuncExtensions.Apply<T1, T2, T3, TResult>(this System.Func<T1, T2, T3, TResult>! function, T1 arg1, Funcky.Unit arg2, Funcky.Unit arg3) -> System.Func<T2, T3, TResult>!
6+
static Funcky.Extensions.FuncExtensions.Apply<T1, T2, T3, TResult>(this System.Func<T1, T2, T3, TResult>! function, T1 arg1, Funcky.Unit arg2, T3 arg3) -> System.Func<T2, TResult>!
7+
static Funcky.Extensions.FuncExtensions.Apply<T1, T2, T3, TResult>(this System.Func<T1, T2, T3, TResult>! function, T1 arg1, T2 arg2, Funcky.Unit arg3) -> System.Func<T3, TResult>!
8+
static Funcky.Extensions.FuncExtensions.Apply<T1, T2, TResult>(this System.Func<T1, T2, TResult>! function, Funcky.Unit arg1, T2 arg2) -> System.Func<T1, TResult>!
9+
static Funcky.Extensions.FuncExtensions.Apply<T1, T2, TResult>(this System.Func<T1, T2, TResult>! function, T1 arg1, Funcky.Unit arg2) -> System.Func<T2, TResult>!

0 commit comments

Comments
 (0)