Exemplo n.º 1
0
        public async Task <decimal> Calculate()
        {
            var(initiator, commandStack) = _commandLexer
                                           .CreateExecutableStack(
                _commandParser.ParseInstructions(
                    await _commandExtractor.Extract().ConfigureAwait(false)));

            decimal result = initiator;

            while (commandStack.TryPop(out var instruction))
            {
                var(command, value) = instruction;
                result = _operators[command].Invoke(result, value);
            }

            return(result);
        }