Last active
March 12, 2023 14:19
-
-
Save bgoetzmann/aa830ed911f275dc3dfded4a73b9a50d to your computer and use it in GitHub Desktop.
Used in this article: https://medium.com/@bgoetzmann/modèle-de-conception-commande-en-langage-groovy-9bea26b47d6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _makeAddItemCommand(Item item) { | |
{ Cart cart -> cart.addItem(item) } | |
} | |
def _makeRemoveItemCommand(Item item) { | |
{ Cart cart -> cart.removeItem(item) } | |
} | |
def actions = [ | |
_makeAddItemCommand(new Item(name: 'Item1', price: 1)), | |
_makeAddItemCommand(new Item(name: 'Item2', price: 1)), | |
_makeRemoveItemCommand(new Item(name: 'Item1', price: 1)) | |
] | |
def _fpCart = new Cart() | |
actions*.call(_fpCart) | |
assert _fpCart.items.keySet() == ['Item2'] as Set |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment