Example #1
0
        public void PipeToParams_ThreeAdittionalArgs_PipesToParams()
        {
            // ----------------------- Arrange -----------------------
            ParamFunc <int, int, int, int, int> sum = (x, y, z, args) => (x * args.Sum() - y) << z;

            // -----------------------   Act   -----------------------
            int aggregate = new[] { 1, 2, 3 }.PipeToParams(sum, 2, 1, 3);

            // -----------------------  Assert -----------------------
            Assert.AreEqual(88, aggregate);
        }
Example #2
0
        public void PipeToParams_FourAdittionalArgs_PipeToParams()
        {
            // ----------------------- Arrange -----------------------
            ParamFunc <int, int, int, int, int, int> sum = (a, x, y, z, args) => a + ((x * args.Sum() - y) << z);

            // -----------------------   Act   -----------------------
            int aggregate = new[] { 1, 2, 3 }.PipeToParams(sum, 1, 2, 1, 3);

            // -----------------------  Assert -----------------------
            Assert.AreEqual(89, aggregate);
        }
Example #3
0
        public void PipeToParams_NoAdittionalArgs_PipesToParams()
        {
            // ----------------------- Arrange -----------------------
            ParamFunc <int, int> sum = args => args.Sum();

            // -----------------------   Act   -----------------------
            int aggregate = new [] { 1, 2, 3 }.PipeToParams(sum);

            // -----------------------  Assert -----------------------
            Assert.AreEqual(6, aggregate);
        }
Example #4
0
        public void PipeToParams_TwoAdittionalArgs_PipesToParams()
        {
            // ----------------------- Arrange -----------------------
            ParamFunc <int, int, int, int> sum = (x, y, args) => x *args.Sum() - y;

            // -----------------------   Act   -----------------------
            int aggregate = new[] { 1, 2, 3 }.PipeToParams(sum, 2, 1);

            // -----------------------  Assert -----------------------
            Assert.AreEqual(11, aggregate);
        }
Example #5
0
        public void Curry_ParameterizedDelegateFourLeadingParams_Curries()
        {
            // ----------------------- Arrange -----------------------
            ParamFunc <int, int, int, int, int, int> add = (x, y, z, a, args) => x *y *z *a *args.Sum();

            // -----------------------   Act   -----------------------
            ParamFunc <int, int, int, int, int> addDouble = add.Curry(2);

            //----------- Assert-------------------------------
            Assert.True(addDouble(1, 1, 1, 1, 1, 1) == 6);
        }
Example #6
0
 /// <summary>
 /// Takes a function and preloads its first argument with the specified value.
 /// </summary>
 public static ParamFunc <TData, TResult> Curry <TData, TResult>(
     this ParamFunc <TData, TResult> function,
     TData value)
 {
     return(data =>
     {
         TData[] parameters = new TData[data.Length + 1];
         parameters[0] = value;
         data.CopyTo(parameters, 1);
         return function(parameters.ToArray());
     });
 }
Example #7
0
        public void Curry_ParameterizedDelegate_Curries()
        {
            // ----------------------- Arrange -----------------------
            ParamFunc <int, int> add = args => args.Sum();

            // -----------------------   Act   -----------------------
            ParamFunc <int, int> add3 = add.Curry(3);

            // -----------------------  Assert -----------------------
            Assert.True(add3(1) == 4);
            Assert.True(add3(1, 2, 3, 6, 9) == 24);
            Assert.True(add3() == 3);
            Assert.True(add3(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) == 3);
        }
Example #8
0
 /// <summary>
 /// Takes pipe input and passes it to the params argument of a ParamFunc.
 /// </summary>
 public static TResult PipeToParams <T1, T2, T3, T4, TData, TResult>(this TData[] data, ParamFunc <T1, T2, T3, T4, TData, TResult> function, T1 value1, T2 value2, T3 value3, T4 value4)
 {
     return(function(value1, value2, value3, value4, data));
 }
Example #9
0
 /// <summary>
 /// Takes pipe input and passes it to the params argument of a ParamFunc.
 /// </summary>
 public static TResult PipeToParams <T1, TData, TResult>(this TData[] data, ParamFunc <T1, TData, TResult> function, T1 value1)
 {
     return(function(value1, data));
 }
Example #10
0
 /// <summary>
 /// Takes pipe input and passes it to the params argument of a ParamFunc.
 /// </summary>
 public static TResult PipeToParams <TData, TResult>(this TData[] data, ParamFunc <TData, TResult> func)
 {
     return(func(data));
 }
Example #11
0
 /// <summary>
 /// Takes a function and preloads its first argument with the specified value.
 /// </summary>
 public static ParamFunc <T2, T3, T4, TData, TResult> Curry <T1, T2, T3, T4, TData, TResult>(
     this ParamFunc <T1, T2, T3, T4, TData, TResult> function, T1 value)
 {
     return((x, y, z, data) => function(value, x, y, z, data));
 }
Example #12
0
 /// <summary>
 /// Takes a function and preloads its first argument with the specified value.
 /// </summary>
 public static ParamFunc <TData, TResult> Curry <T1, TData, TResult>(
     this ParamFunc <T1, TData, TResult> function, T1 value)
 {
     return(data => function(value, data));
 }
Example #13
0
 public void AddData(int paramIndex, ParamFunc func)
 {
     patterns.Add(func);
     paramIndices.Add(paramIndex);
 }