public T Accumulate(INumericalOperation procName, List <INumber> operands) { var operandList = operands.ConvertAll(x => x as T); var accProc = procArith[procName.GetType()]; var init = default(T); if (procName is ScmAddition) { init = GetZero(); } else if (procName is ScmMultiplication) { init = GetOne(); } else if (procName is ScmMinProcedure || procName is ScmMaxProcedure) { if (operandList.Count < 2) { throw new Exception("Expects at least 2 argument"); } init = null; } else { if (operandList.IsEmpty()) { throw new Exception("Expects at least 1 argument"); } if (operandList.IsSingle()) { if (procName is ScmDivision) { operandList.Insert(0, GetOne()); } else { operandList.Insert(0, GetZero()); } } init = operandList.Head(); operandList = operandList.Tail(); } return(Utils.AccumulateList(accProc, operandList, init)); }
public virtual Utils.AccumulateProc <T> GetProc(INumericalOperation procName) { return(procArith[procName.GetType()]); }