reduce() public method

Reduce the collection using a function.
Computes f(...f(f(f(i0,i1),i2),i3),...).
public reduce ( IFn f ) : object
f IFn The function to apply.
return object
Beispiel #1
0
        public void ReduceWithStartIterates()
        {
            IFn fn = DummyFn.CreateForReduce();

            Range r = new Range(2, 5);
            object ret = r.reduce(fn, 20);

            Expect(ret, EqualTo(29));
        }
Beispiel #2
0
        public void ReduceWithNoStartIterates()
        {
            MockRepository mocks = new MockRepository();
            IFn fn = mocks.StrictMock<IFn>();
            RMExpect.Call(fn.invoke(2, 3)).Return(5);
            RMExpect.Call(fn.invoke(5, 4)).Return(7);
            mocks.ReplayAll();

            Range r = new Range(2, 5);
            object ret = r.reduce(fn);

            Expect(ret, EqualTo(7));

            mocks.VerifyAll();
        }