/// <summary>
 /// returns a string representation of the expression.
 /// </summary>
 /// <param name="element">The expression to inspect.</param>
 public static string Inspect(this IReducible element)
 {
     return(string.Format(
                CultureInfo.InvariantCulture,
                "«{0}»",
                element));
 }
Beispiel #2
0
 /// <summary>
 /// Calculates the minimum absolute value of all entries of an <see cref="IReducible"/>.
 /// </summary>
 /// <param name="reducible">A matrix, vector or similar collection.</param>
 public static double MinAbsolute(this IReducible reducible)
 {
     return(reducible.Reduce(double.MaxValue, (x, min) =>
     {
         double abs = Math.Abs(x);
         return abs < min ? abs : min;
     },
                             (nz, min) => 0.0 < min ? 0.0 : min, min => min));
 }
Beispiel #3
0
 /// <summary>
 /// Calculates the maximum absolute value of all entries of an <see cref="IReducible"/>.
 /// </summary>
 /// <param name="reducible">A matrix, vector or similar collection.</param>
 public static double MaxAbsolute(this IReducible reducible)
 {
     return(reducible.Reduce(double.MinValue, (x, max) =>
     {
         double abs = Math.Abs(x);
         return abs > max ? abs : max;
     },
                             (nz, max) => 0.0 > max ? 0.0 : max, max => max));
 }
        internal static object ReduceInternal(object fn, object acc, object list)
        {
            IReducible   reducible   = null;
            ITransformer transformer = fn as ITransformer;

            if (fn.IsFunction())
            {
                transformer = new XWrap((dynamic)fn);
            }

            if (R.IsArrayLike(list))
            {
                return(IterableReduce(transformer, acc, (IEnumerable)list));
            }

            reducible = list as IReducible;

            if (reducible.IsNotNull())
            {
                return(MethodReduce(transformer, acc, reducible));
            }

            throw new ArgumentException("Reduce: list must be array or iterable");
        }
Beispiel #5
0
 /// <summary>
 /// Transforms the items of the list with the transducer and appends thetransformed items to the accumulator using an appropriate iterator functionbased on the accumulator type.The accumulator can be an array, string, object or a transformer. Iterateditems will be appended to arrays and concatenated to strings. Objects willbe merged directly or 2-item arrays will be merged as key, value pairs.The accumulator can also be a transformer object that provides a 2-arityreducing iterator function, step, 0-arity initial value function, init, and1-arity result extraction function result. The step function is used as theiterator function in reduce. The result function is used to convert thefinal accumulator into the return type and in most cases is R.identity. Theinit function is used to provide the initial accumulator.The iteration is performed with R.reduce after initializing the transducer.
 /// <para />
 /// sig: a -> (b -> b) -> [c] -> a
 /// </summary>
 /// <param name="acc">The initial accumulator value.</param>
 /// <param name="xf">The transducer function. Receives a transformer and returns a transformer.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 public static dynamic Into(RamdaPlaceholder acc, dynamic xf, IReducible list)
 {
     return(Currying.Into(acc, Delegate(xf), list));
 }
Beispiel #6
0
 /// <summary>
 /// Transforms the items of the list with the transducer and appends thetransformed items to the accumulator using an appropriate iterator functionbased on the accumulator type.The accumulator can be an array, string, object or a transformer. Iterateditems will be appended to arrays and concatenated to strings. Objects willbe merged directly or 2-item arrays will be merged as key, value pairs.The accumulator can also be a transformer object that provides a 2-arityreducing iterator function, step, 0-arity initial value function, init, and1-arity result extraction function result. The step function is used as theiterator function in reduce. The result function is used to convert thefinal accumulator into the return type and in most cases is R.identity. Theinit function is used to provide the initial accumulator.The iteration is performed with R.reduce after initializing the transducer.
 /// <para />
 /// sig: a -> (b -> b) -> [c] -> a
 /// </summary>
 /// <param name="acc">The initial accumulator value.</param>
 /// <param name="xf">The transducer function. Receives a transformer and returns a transformer.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 public static dynamic Into <TAccumulator>(IList <TAccumulator> acc, RamdaPlaceholder xf, IReducible list)
 {
     return(Currying.Into(acc, xf, list));
 }
Beispiel #7
0
 /// <summary>
 /// Initializes a transducer using supplied iterator function. Returns a singleitem by iterating through the list, successively calling the transformediterator function and passing it an accumulator value and the current valuefrom the array, and then passing the result to the next call.The iterator function receives two values: *(acc, value)*. It will bewrapped as a transformer to initialize the transducer. A transformer can bepassed directly in place of an iterator function. In both cases, iterationmay be stopped early with the `R.reduced` function.A transducer is a function that accepts a transformer and returns atransformer and can be composed directly.A transformer is an an object that provides a 2-arity reducing iteratorfunction, step, 0-arity initial value function, init, and 1-arity resultextraction function, result. The step function is used as the iteratorfunction in reduce. The result function is used to convert the finalaccumulator into the return type and in most cases is R.identity. The initfunction can be used to provide an initial accumulator, but is ignored bytransduce.The iteration is performed with R.reduce after initializing the transducer.
 /// <para />
 /// sig: (c -> c) -> (a,b -> a) -> a -> [b] -> a
 /// </summary>
 /// <param name="xf">The transducer function. Receives a transformer and returns a transformer.</param>
 /// <param name="fn">The iterator function. Receives two values, the accumulator and the       current element from the array. Wrapped as transformer, if necessary, and used to       initialize the transducer</param>
 /// <param name="acc">The initial accumulator value.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 /// <see cref="R.Reduce"/>
 /// <see cref="R.Reduced"/>
 /// <see cref="R.Into"/>
 public static dynamic Transduce <TAccumulator>(dynamic xf, RamdaPlaceholder fn, TAccumulator acc, IReducible list)
 {
     return(Currying.Transduce(Delegate(xf), fn, acc, list));
 }
Beispiel #8
0
 /// <summary>
 /// Calculates the product over all entries of an <see cref="IReducible"/>.
 /// </summary>
 /// <param name="reducible">A matrix, vector or similar collection.</param>
 public static double Product(this IReducible reducible)
 {
     return(reducible.Reduce(1.0, (x, prod) => x * prod, (nz, prod) => nz > 0 ? 0 : prod, prod => prod));
 }
Beispiel #9
0
 /// <summary>
 /// Transforms the items of the list with the transducer and appends thetransformed items to the accumulator using an appropriate iterator functionbased on the accumulator type.The accumulator can be an array, string, object or a transformer. Iterateditems will be appended to arrays and concatenated to strings. Objects willbe merged directly or 2-item arrays will be merged as key, value pairs.The accumulator can also be a transformer object that provides a 2-arityreducing iterator function, step, 0-arity initial value function, init, and1-arity result extraction function result. The step function is used as theiterator function in reduce. The result function is used to convert thefinal accumulator into the return type and in most cases is R.identity. Theinit function is used to provide the initial accumulator.The iteration is performed with R.reduce after initializing the transducer.
 /// <para />
 /// sig: a -> (b -> b) -> [c] -> a
 /// </summary>
 /// <param name="acc">The initial accumulator value.</param>
 /// <param name="xf">The transducer function. Receives a transformer and returns a transformer.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 public static dynamic Into(ExpandoObject acc, Func <ITransformer, ITransformer> xf, IReducible list)
 {
     return(Currying.Into(acc, Delegate(xf), list));
 }
Beispiel #10
0
 /// <summary>
 /// Returns a single item by iterating through the list, successively callingthe iterator function and passing it an accumulator value and the currentvalue from the array, and then passing the result to the next call.The iterator function receives two values: *(acc, value)*. It may use`R.reduced` to shortcut the iteration.The arguments' order of `reduceRight`'s iterator function is *(value, acc)*.Note: `R.reduce` does not skip deleted or unassigned indices (sparsearrays), unlike the native `Array.prototype.reduce` method. For more detailson this behavior, see:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#DescriptionDispatches to the `reduce` method of the third argument, if present.
 /// <para />
 /// sig: ((a, b) -> a) -> a -> [b] -> a
 /// </summary>
 /// <param name="fn">The iterator function. Receives two values, the accumulator and the       current element from the array.</param>
 /// <param name="acc">The accumulator value.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 /// <see cref="R.Reduced"/>
 /// <see cref="R.AddIndex"/>
 /// <see cref="R.Reduce"/>
 public static dynamic Reduce(dynamic fn, RamdaPlaceholder acc, IReducible list)
 {
     return(Currying.Reduce(Delegate(fn), acc, list));
 }
Beispiel #11
0
 /// <summary>
 /// Returns a single item by iterating through the list, successively callingthe iterator function and passing it an accumulator value and the currentvalue from the array, and then passing the result to the next call.The iterator function receives two values: *(acc, value)*. It may use`R.reduced` to shortcut the iteration.The arguments' order of `reduceRight`'s iterator function is *(value, acc)*.Note: `R.reduce` does not skip deleted or unassigned indices (sparsearrays), unlike the native `Array.prototype.reduce` method. For more detailson this behavior, see:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#DescriptionDispatches to the `reduce` method of the third argument, if present.
 /// <para />
 /// sig: ((a, b) -> a) -> a -> [b] -> a
 /// </summary>
 /// <param name="fn">The iterator function. Receives two values, the accumulator and the       current element from the array.</param>
 /// <param name="acc">The accumulator value.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 /// <see cref="R.Reduced"/>
 /// <see cref="R.AddIndex"/>
 /// <see cref="R.Reduce"/>
 public static dynamic Reduce <TSource, TReturn, TAccmulator>(Func <TSource, TAccmulator, TReturn> fn, RamdaPlaceholder acc, IReducible list)
 {
     return(Currying.Reduce(Delegate(fn), acc, list));
 }
Beispiel #12
0
 /// <summary>
 /// Returns a single item by iterating through the list, successively callingthe iterator function and passing it an accumulator value and the currentvalue from the array, and then passing the result to the next call.The iterator function receives two values: *(acc, value)*. It may use`R.reduced` to shortcut the iteration.The arguments' order of `reduceRight`'s iterator function is *(value, acc)*.Note: `R.reduce` does not skip deleted or unassigned indices (sparsearrays), unlike the native `Array.prototype.reduce` method. For more detailson this behavior, see:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#DescriptionDispatches to the `reduce` method of the third argument, if present.
 /// <para />
 /// sig: ((a, b) -> a) -> a -> [b] -> a
 /// </summary>
 /// <param name="fn">The iterator function. Receives two values, the accumulator and the       current element from the array.</param>
 /// <param name="acc">The accumulator value.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 /// <see cref="R.Reduced"/>
 /// <see cref="R.AddIndex"/>
 /// <see cref="R.Reduce"/>
 public static dynamic Reduce <TAccmulator>(RamdaPlaceholder fn, TAccmulator acc, IReducible list)
 {
     return(Currying.Reduce(fn, acc, list));
 }
Beispiel #13
0
 /// <summary>
 /// Returns a single item by iterating through the list, successively callingthe iterator function and passing it an accumulator value and the currentvalue from the array, and then passing the result to the next call.The iterator function receives two values: *(acc, value)*. It may use`R.reduced` to shortcut the iteration.The arguments' order of `reduceRight`'s iterator function is *(value, acc)*.Note: `R.reduce` does not skip deleted or unassigned indices (sparsearrays), unlike the native `Array.prototype.reduce` method. For more detailson this behavior, see:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#DescriptionDispatches to the `reduce` method of the third argument, if present.
 /// <para />
 /// sig: ((a, b) -> a) -> a -> [b] -> a
 /// </summary>
 /// <param name="fn">The iterator function. Receives two values, the accumulator and the       current element from the array.</param>
 /// <param name="acc">The accumulator value.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 /// <see cref="R.Reduced"/>
 /// <see cref="R.AddIndex"/>
 /// <see cref="R.Reduce"/>
 public static dynamic Reduce <TAccmulator>(dynamic fn, TAccmulator acc, IReducible list)
 {
     return(Currying.Reduce(Delegate(fn), acc, list));
 }
Beispiel #14
0
 /// <summary>
 /// Initializes a transducer using supplied iterator function. Returns a singleitem by iterating through the list, successively calling the transformediterator function and passing it an accumulator value and the current valuefrom the array, and then passing the result to the next call.The iterator function receives two values: *(acc, value)*. It will bewrapped as a transformer to initialize the transducer. A transformer can bepassed directly in place of an iterator function. In both cases, iterationmay be stopped early with the `R.reduced` function.A transducer is a function that accepts a transformer and returns atransformer and can be composed directly.A transformer is an an object that provides a 2-arity reducing iteratorfunction, step, 0-arity initial value function, init, and 1-arity resultextraction function, result. The step function is used as the iteratorfunction in reduce. The result function is used to convert the finalaccumulator into the return type and in most cases is R.identity. The initfunction can be used to provide an initial accumulator, but is ignored bytransduce.The iteration is performed with R.reduce after initializing the transducer.
 /// <para />
 /// sig: (c -> c) -> (a,b -> a) -> a -> [b] -> a
 /// </summary>
 /// <param name="xf">The transducer function. Receives a transformer and returns a transformer.</param>
 /// <param name="fn">The iterator function. Receives two values, the accumulator and the       current element from the array. Wrapped as transformer, if necessary, and used to       initialize the transducer</param>
 /// <param name="acc">The initial accumulator value.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 /// <see cref="R.Reduce"/>
 /// <see cref="R.Reduced"/>
 /// <see cref="R.Into"/>
 public static dynamic Transduce <TAccumulator>(Func <ITransformer, ITransformer> xf, Func <TAccumulator, ITransformer> fn, RamdaPlaceholder acc, IReducible list)
 {
     return(Currying.Transduce(Delegate(xf), Delegate(fn), acc, list));
 }
Beispiel #15
0
 /// <summary>
 /// Initializes a transducer using supplied iterator function. Returns a singleitem by iterating through the list, successively calling the transformediterator function and passing it an accumulator value and the current valuefrom the array, and then passing the result to the next call.The iterator function receives two values: *(acc, value)*. It will bewrapped as a transformer to initialize the transducer. A transformer can bepassed directly in place of an iterator function. In both cases, iterationmay be stopped early with the `R.reduced` function.A transducer is a function that accepts a transformer and returns atransformer and can be composed directly.A transformer is an an object that provides a 2-arity reducing iteratorfunction, step, 0-arity initial value function, init, and 1-arity resultextraction function, result. The step function is used as the iteratorfunction in reduce. The result function is used to convert the finalaccumulator into the return type and in most cases is R.identity. The initfunction can be used to provide an initial accumulator, but is ignored bytransduce.The iteration is performed with R.reduce after initializing the transducer.
 /// <para />
 /// sig: (c -> c) -> (a,b -> a) -> a -> [b] -> a
 /// </summary>
 /// <param name="xf">The transducer function. Receives a transformer and returns a transformer.</param>
 /// <param name="fn">The iterator function. Receives two values, the accumulator and the       current element from the array. Wrapped as transformer, if necessary, and used to       initialize the transducer</param>
 /// <param name="acc">The initial accumulator value.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 /// <see cref="R.Reduce"/>
 /// <see cref="R.Reduced"/>
 /// <see cref="R.Into"/>
 public static dynamic Transduce <TAccumulator>(dynamic xf, dynamic fn, TAccumulator acc, IReducible list)
 {
     return(Currying.Transduce(Delegate(xf), Delegate(fn), acc, list));
 }
Beispiel #16
0
 /// <summary>
 /// Transforms the items of the list with the transducer and appends thetransformed items to the accumulator using an appropriate iterator functionbased on the accumulator type.The accumulator can be an array, string, object or a transformer. Iterateditems will be appended to arrays and concatenated to strings. Objects willbe merged directly or 2-item arrays will be merged as key, value pairs.The accumulator can also be a transformer object that provides a 2-arityreducing iterator function, step, 0-arity initial value function, init, and1-arity result extraction function result. The step function is used as theiterator function in reduce. The result function is used to convert thefinal accumulator into the return type and in most cases is R.identity. Theinit function is used to provide the initial accumulator.The iteration is performed with R.reduce after initializing the transducer.
 /// <para />
 /// sig: a -> (b -> b) -> [c] -> a
 /// </summary>
 /// <param name="acc">The initial accumulator value.</param>
 /// <param name="xf">The transducer function. Receives a transformer and returns a transformer.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 public static dynamic Into(ExpandoObject acc, RamdaPlaceholder xf, IReducible list)
 {
     return(Currying.Into(acc, xf, list));
 }
Beispiel #17
0
 /// <summary>
 /// Calculates the maximum value of all entries of an <see cref="IReducible"/>.
 /// </summary>
 /// <param name="reducible">A matrix, vector or similar collection.</param>
 public static double Max(this IReducible reducible)
 {
     return(reducible.Reduce(double.MinValue, (x, max) => x > max ? x : max,
                             (nz, max) => 0.0 > max ? 0.0 : max, max => max));
 }
Beispiel #18
0
 /// <summary>
 /// Transforms the items of the list with the transducer and appends thetransformed items to the accumulator using an appropriate iterator functionbased on the accumulator type.The accumulator can be an array, string, object or a transformer. Iterateditems will be appended to arrays and concatenated to strings. Objects willbe merged directly or 2-item arrays will be merged as key, value pairs.The accumulator can also be a transformer object that provides a 2-arityreducing iterator function, step, 0-arity initial value function, init, and1-arity result extraction function result. The step function is used as theiterator function in reduce. The result function is used to convert thefinal accumulator into the return type and in most cases is R.identity. Theinit function is used to provide the initial accumulator.The iteration is performed with R.reduce after initializing the transducer.
 /// <para />
 /// sig: a -> (b -> b) -> [c] -> a
 /// </summary>
 /// <param name="acc">The initial accumulator value.</param>
 /// <param name="xf">The transducer function. Receives a transformer and returns a transformer.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 public static dynamic Into(ExpandoObject acc, dynamic xf, IReducible list)
 {
     return(Currying.Into(acc, Delegate(xf), list));
 }
Beispiel #19
0
 /// <summary>
 /// Calculates the minimum value of all entries of an <see cref="IReducible"/>.
 /// </summary>
 /// <param name="reducible">A matrix, vector or similar collection.</param>
 public static double Min(this IReducible reducible)
 {
     return(reducible.Reduce(double.MaxValue, (x, min) => x < min ? x : min,
                             (nz, min) => 0.0 < min ? 0.0 : min, min => min));
 }
Beispiel #20
0
 /// <summary>
 /// Transforms the items of the list with the transducer and appends thetransformed items to the accumulator using an appropriate iterator functionbased on the accumulator type.The accumulator can be an array, string, object or a transformer. Iterateditems will be appended to arrays and concatenated to strings. Objects willbe merged directly or 2-item arrays will be merged as key, value pairs.The accumulator can also be a transformer object that provides a 2-arityreducing iterator function, step, 0-arity initial value function, init, and1-arity result extraction function result. The step function is used as theiterator function in reduce. The result function is used to convert thefinal accumulator into the return type and in most cases is R.identity. Theinit function is used to provide the initial accumulator.The iteration is performed with R.reduce after initializing the transducer.
 /// <para />
 /// sig: a -> (b -> b) -> [c] -> a
 /// </summary>
 /// <param name="acc">The initial accumulator value.</param>
 /// <param name="xf">The transducer function. Receives a transformer and returns a transformer.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 public static dynamic Into <TAccumulator>(IList <TAccumulator> acc, dynamic xf, IReducible list)
 {
     return(Currying.Into(acc, Delegate(xf), list));
 }
Beispiel #21
0
 /// <summary>
 /// Calculates the Euclidian norm or 2-norm over all entries of an <see cref="IReducible"/>. For more see
 /// https://en.wikipedia.org/wiki/Norm_(mathematics)#Euclidean_norm. WARNING: most classes that implement
 /// <see cref="IReducible"/> will provide far more efficient methods for calculating norms. Use them instead.
 /// </summary>
 /// <param name="reducible">A matrix, vector or similar collection.</param>
 public static double Norm2(this IReducible reducible)
 {
     return(reducible.Reduce(0.0, (x, sum) => x + sum, (nz, sum) => sum, sum => Math.Sqrt(sum)));
 }
Beispiel #22
0
 /// <summary>
 /// Transforms the items of the list with the transducer and appends thetransformed items to the accumulator using an appropriate iterator functionbased on the accumulator type.The accumulator can be an array, string, object or a transformer. Iterateditems will be appended to arrays and concatenated to strings. Objects willbe merged directly or 2-item arrays will be merged as key, value pairs.The accumulator can also be a transformer object that provides a 2-arityreducing iterator function, step, 0-arity initial value function, init, and1-arity result extraction function result. The step function is used as theiterator function in reduce. The result function is used to convert thefinal accumulator into the return type and in most cases is R.identity. Theinit function is used to provide the initial accumulator.The iteration is performed with R.reduce after initializing the transducer.
 /// <para />
 /// sig: a -> (b -> b) -> [c] -> a
 /// </summary>
 /// <param name="acc">The initial accumulator value.</param>
 /// <param name="xf">The transducer function. Receives a transformer and returns a transformer.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 public static dynamic Into <TAccumulator>(IList <TAccumulator> acc, Func <ITransformer, ITransformer> xf, IReducible list)
 {
     return(Currying.Into(acc, Delegate(xf), list));
 }
Beispiel #23
0
 /// <summary>
 /// Calculates the sum over all entries of an <see cref="IReducible"/>.
 /// </summary>
 /// <param name="reducible">A matrix, vector or similar collection.</param>
 public static double Sum(this IReducible reducible)
 {
     return(reducible.Reduce(0.0, (x, sum) => x + sum, (nz, sum) => sum, sum => sum));
 }
Beispiel #24
0
 /// <summary>
 /// Transforms the items of the list with the transducer and appends thetransformed items to the accumulator using an appropriate iterator functionbased on the accumulator type.The accumulator can be an array, string, object or a transformer. Iterateditems will be appended to arrays and concatenated to strings. Objects willbe merged directly or 2-item arrays will be merged as key, value pairs.The accumulator can also be a transformer object that provides a 2-arityreducing iterator function, step, 0-arity initial value function, init, and1-arity result extraction function result. The step function is used as theiterator function in reduce. The result function is used to convert thefinal accumulator into the return type and in most cases is R.identity. Theinit function is used to provide the initial accumulator.The iteration is performed with R.reduce after initializing the transducer.
 /// <para />
 /// sig: a -> (b -> b) -> [c] -> a
 /// </summary>
 /// <param name="acc">The initial accumulator value.</param>
 /// <param name="xf">The transducer function. Receives a transformer and returns a transformer.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 public static dynamic Into(RamdaPlaceholder acc, Func <ITransformer, ITransformer> xf, IReducible list)
 {
     return(Currying.Into(acc, Delegate(xf), list));
 }
 private static object MethodReduce(ITransformer xf, object acc, IReducible obj)
 {
     return(xf.Result(obj.Reduce(new Func <object, object, object>(xf.Step), acc)));
 }
Beispiel #26
0
 /// <summary>
 /// Initializes a transducer using supplied iterator function. Returns a singleitem by iterating through the list, successively calling the transformediterator function and passing it an accumulator value and the current valuefrom the array, and then passing the result to the next call.The iterator function receives two values: *(acc, value)*. It will bewrapped as a transformer to initialize the transducer. A transformer can bepassed directly in place of an iterator function. In both cases, iterationmay be stopped early with the `R.reduced` function.A transducer is a function that accepts a transformer and returns atransformer and can be composed directly.A transformer is an an object that provides a 2-arity reducing iteratorfunction, step, 0-arity initial value function, init, and 1-arity resultextraction function, result. The step function is used as the iteratorfunction in reduce. The result function is used to convert the finalaccumulator into the return type and in most cases is R.identity. The initfunction can be used to provide an initial accumulator, but is ignored bytransduce.The iteration is performed with R.reduce after initializing the transducer.
 /// <para />
 /// sig: (c -> c) -> (a,b -> a) -> a -> [b] -> a
 /// </summary>
 /// <param name="xf">The transducer function. Receives a transformer and returns a transformer.</param>
 /// <param name="fn">The iterator function. Receives two values, the accumulator and the       current element from the array. Wrapped as transformer, if necessary, and used to       initialize the transducer</param>
 /// <param name="acc">The initial accumulator value.</param>
 /// <param name="list">The list to iterate over.</param>
 /// <returns>The final, accumulated value.</returns>
 /// <see cref="R.Reduce"/>
 /// <see cref="R.Reduced"/>
 /// <see cref="R.Into"/>
 public static dynamic Transduce <TAccumulator>(RamdaPlaceholder xf, dynamic fn, TAccumulator acc, IReducible list)
 {
     return(Currying.Transduce(xf, Delegate(fn), acc, list));
 }