private decimal Reduce(string expression, char operation, Func<string, decimal> furtherReduction) { var tokens = expression.Split(operation); Operand operand = furtherReduction(tokens[0]); for (int i = 1; i < tokens.Length; i++) { operand = new Operand(operand, furtherReduction(tokens[i]), operation); } return operand; }
public Operand(Operand firstOperand, Operand secondOperand, char operation) { Value = secondOperand == null ? firstOperand.Value : _operationDefinitions[operation](firstOperand, secondOperand); }