public (CommandStatus commandStatus, Event[] events, Notification[] notifications) Execute(Decrement command, Model model) { if (model.RegisteredNames.Contains(command.Name) is false) { return(new Failure("Dat war nix!"), new Event[0], new Notification[0]); } var e = new Decremented { Name = command.Name }; return(new Success(), new Event[] { e }, new Notification[0]); }
public Value.Result Handle(Value query) { return(new Value.Result { Value = _es.Replay() .Where(Filter) .Select(Apply).Sum() }); bool Filter(Event e) => e switch { Incremented i => i.Name == query.Name, Decremented d => d.Name == query.Name }; int Apply(Event e) => e switch { Incremented _ => 1, Decremented _ => - 1 }; } }