Skip to content

Commit

Permalink
Discard was merged, updated the pull request wit overloads for 2 and …
Browse files Browse the repository at this point in the history
…3 parameters.
  • Loading branch information
FreeApophis committed May 17, 2023
1 parent b735e84 commit 856050e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Funcky.Test/FunctionalClass/ApplyTest.cs
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);
}
30 changes: 30 additions & 0 deletions Funcky/Extensions/FuncExtensions/Apply.cs
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);
}
8 changes: 8 additions & 0 deletions Funcky/PublicAPI.Unshipped.txt
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>!

0 comments on commit 856050e

Please sign in to comment.