Skip to content

Instantly share code, notes, and snippets.

@justinhj
Last active January 19, 2020 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinhj/5913ee8f1af6cbabc3c93eff6279b439 to your computer and use it in GitHub Desktop.
Save justinhj/5913ee8f1af6cbabc3c93eff6279b439 to your computer and use it in GitHub Desktop.
val (finalEntity, finalEvents) =
commands.foldLeft((sampleAccount, List.empty[BankAccountEvent])) {
case ((acc, events), cmd) =>
val newEvents = acc.processCommand(cmd)
val newAcc = newEvents.foldLeft(acc) {
case (acc, evt) =>
acc.processEvent(evt)
}
(newAcc, events ++ newEvents)
}
println(show"Final state 1:\n${finalEntity.state}")
/* Output:
Final state 1:
Account holder: Ben Johnson
Balance: 80
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment