예제 #1
0
    //Reduce -- done synchronously
    public T Reduce(ReduceWork rw)
    {
        //if mCount is 0 then throws IndexOutOfRangeException
        if (mCount == 0)
        {
            throw new IndexOutOfRangeException();
        }

        //initial value is the first element
        var cur = mList[0];

        //loop through the other elements, if there are any
        for (int i = 1; i < mCount; i++)
        {
            //update the accumulator using rw
            cur = rw(cur, mList[i]);
        }
        //return the accumulation
        return(cur);
    }
예제 #2
0
 //Reduce -- done asynchronously
 public async Task <T> ReduceAsync(ReduceWork rw)
 {
     //do reduce asynchronously and return the Task<T> that belongs to it
     return(await Task.Run(() => { return Reduce(rw); }));
 }