-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Discard was merged, updated the pull request wit overloads for 2 and …
…3 parameters.
- Loading branch information
1 parent
b735e84
commit 856050e
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using static Funcky.Discard; | ||
|
||
namespace Funcky.Test.Extensions.FuncExtensions; | ||
|
||
public class ApplyTest | ||
{ | ||
[Fact] | ||
public void CanApplyParametersInAnyOrder() | ||
{ | ||
var func = Linear0; | ||
|
||
var f1 = ((Func<int, int, int, int>)Linear0).Apply(__, __, 10); | ||
var f2 = func.Apply(2, __, 7); | ||
var f3 = Funcky.Extensions.FuncExtensions.Apply<int, int, int, int>(Linear0, __, __, 42); | ||
|
||
Assert.Equal(30, f1(10, 2)); | ||
Assert.Equal(72, f2(10)); | ||
Assert.Equal(30, f3(10, 2)); | ||
} | ||
|
||
[Fact] | ||
public void Test2() | ||
{ | ||
} | ||
|
||
private static int Linear0(int a, int b, int c) | ||
=> a + (b * c); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace Funcky.Extensions; | ||
|
||
public static partial class FuncExtensions | ||
{ | ||
// All overloads for Fuctions with 2 paramters. | ||
public static Func<T1, TResult> Apply<T1, T2, TResult>(this Func<T1, T2, TResult> function, Unit arg1, T2 arg2) | ||
=> (a1) => function(a1, arg2); | ||
|
||
public static Func<T2, TResult> Apply<T1, T2, TResult>(this Func<T1, T2, TResult> function, T1 arg1, Unit arg2) | ||
=> (a2) => function(arg1, a2); | ||
|
||
// All overloads for Fuctions with 3 paramters. | ||
public static Func<T2, T3, TResult> Apply<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> function, T1 arg1, Unit arg2, Unit arg3) | ||
=> (a2, a3) => function(arg1, a2, a3); | ||
|
||
public static Func<T1, T3, TResult> Apply<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> function, Unit arg1, T2 arg2, Unit arg3) | ||
=> (a1, a3) => function(a1, arg2, a3); | ||
|
||
public static Func<T1, T2, TResult> Apply<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> function, Unit arg1, Unit arg2, T3 arg3) | ||
=> (a1, a2) => function(a1, a2, arg3); | ||
|
||
public static Func<T3, TResult> Apply<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> function, T1 arg1, T2 arg2, Unit arg3) | ||
=> a3 => function(arg1, arg2, a3); | ||
|
||
public static Func<T2, TResult> Apply<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> function, T1 arg1, Unit arg2, T3 arg3) | ||
=> a2 => function(arg1, a2, arg3); | ||
|
||
public static Func<T1, TResult> Apply<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> function, Unit arg1, T2 arg2, T3 arg3) | ||
=> a1 => function(a1, arg2, arg3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
#nullable enable | ||
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>! | ||
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>! | ||
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>! | ||
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>! | ||
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>! | ||
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>! | ||
static Funcky.Extensions.FuncExtensions.Apply<T1, T2, TResult>(this System.Func<T1, T2, TResult>! function, Funcky.Unit arg1, T2 arg2) -> System.Func<T1, TResult>! | ||
static Funcky.Extensions.FuncExtensions.Apply<T1, T2, TResult>(this System.Func<T1, T2, TResult>! function, T1 arg1, Funcky.Unit arg2) -> System.Func<T2, TResult>! |