Example #1
0
        public static T Accumulate <T>(IEnumerable <T> enumerable, T initialValue, Functional.BinaryFunction <T, T, T> func)
        {
            T result = initialValue;

            foreach (T t in enumerable)
            {
                result = func(result, t);
            }
            return(result);
        }
Example #2
0
        [Test] public void Not_Function()
        {
            Functional.UnaryFunction <int, bool> func1 = Functional.Not1(Functional.Bind1st <int, bool>(Functional.LessThan <int>, 29));
            Assert.IsTrue(func1(12));  // !(29 < 12) == false;
            Assert.IsFalse(func1(30)); // !(29 < 30) == true;
            Assert.IsTrue(func1(29));  // !(29 < 29) == false;

            Functional.BinaryFunction <int, int, bool> func2 = Functional.Not2 <int, int>(Functional.LessThan <int>);
            Assert.IsFalse(func2(12, 29)); // !(29 < 12) == false;
            Assert.IsTrue(func2(30, 29));  // !(29 < 30) == true;
            Assert.IsTrue(func2(29, 29));  // !(29 < 29) == false;
        }
Example #3
0
 public static OutputIterator <O> Transform <I, O>(InputIterator <I> begin1, InputIterator <I> end1, InputIterator <I> begin2,
                                                   OutputIterator <O> dest, Functional.BinaryFunction <I, I, O> func)
 {
     begin1 = IteratorUtil.Clone(begin1);
     begin2 = IteratorUtil.Clone(begin2);
     dest   = IteratorUtil.Clone(dest);
     for (; !begin1.Equals(end1); begin1.MoveNext(), begin2.MoveNext(), dest.MoveNext())
     {
         dest.Write(func(begin1.Read(), begin2.Read()));
     }
     return(dest);
 }
Example #4
0
        public static T Accumulate <T>(InputIterator <T> begin, InputIterator <T> end, T initialValue, Functional.BinaryFunction <T, T, T> func)
        {
            T result = initialValue;

            for (begin = IteratorUtil.Clone(begin); !begin.Equals(end); begin.MoveNext())
            {
                result = func(result, begin.Read());
            }
            return(result);
        }