Skip to content

Instantly share code, notes, and snippets.

@gregoryyoung
Created August 10, 2012 18:53
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 gregoryyoung/3316744 to your computer and use it in GitHub Desktop.
Save gregoryyoung/3316744 to your computer and use it in GitHub Desktop.
val currentState = events.foldLeft(0)(state, event) => event match {
         case d:InventoryItemDeactivated =>  Deactivated(d.Id, d.Reason)
         case c:InventoryItemCreated => Created(c.Id, c.Name)
         case a:InventoryItemAudited => Audited(a.Id, a.Outcome, a.EndValue)
}
//or extractors ....
//can put logic right there as well lambdas ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment