void Book(MakeTransfer transfer) => accounts.Get(transfer.DebitedAccountId) .Bind(account => account.Debit(transfer.Amount)) .ForEach(newState => { accounts.Save(transfer.DebitedAccountId, newState); swift.Wire(transfer, newState); });
private void doit(Rq rq) { repo .Get(rq.id) .Bind(account => account.Debit(rq.transferAmount)) .ForEach(account => { // There are 2 statements here ... // They have side-effects and its both-together ... // create single Task representing both ops, // and have process that performs both // remove the task ONLY when both carried out // both ops may get performed more than once ... // => make provisions so that both tasks are idempotent repo.Save(rq.id, account); swift.Wire(rq, account); }); }