private static TDelegate CreateDelegate <TDelegate>(MulticastDelegate theDelegate, object[] arguments)
            where TDelegate : class
        {
            var partialApp = new PartialApplication(theDelegate, arguments);

            return(partialApp.AdaptTo <TDelegate>());
        }
    public void L3_P2_UsePartial()
    {
        // Now, this returns me a function (int -> int):
        var addThree = PartialApplication(3);

        // Which I can apply like this:
        var eight     = addThree(5);
        var ten       = addThree(7);
        var eightteen = eight + ten;

        Console.WriteLine(eightteen);

        // I could also directly call this:
        PartialApplication(5)(8);

        // And we can also write the same partial application with a simple lambda:
        Func <int, Func <int, int> > PartialApplication2 = x => y => x + y;
        var r = PartialApplication2(25)(17);

        Console.WriteLine(r);
    }
Пример #3
0
 /// <summary>
 /// Partial apply maybe value to maybe function of arity 2 by using partial apply
 /// </summary>
 public static Maybe <Func <T2, R> > Apply <T1, T2, R>(this Maybe <Func <T1, T2, R> > self, Maybe <T1> arg) =>
 self.IsSome && arg.IsSome
         ? Maybe <Func <T2, R> > .Some(PartialApplication.papply(self.Value, arg.Value))
         : Maybe <Func <T2, R> > .None;