Skip to content

Instantly share code, notes, and snippets.

@bgoetzmann
Last active March 12, 2023 14:21
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 bgoetzmann/4b7c3bf851b15310148c67815b2b9905 to your computer and use it in GitHub Desktop.
Save bgoetzmann/4b7c3bf851b15310148c67815b2b9905 to your computer and use it in GitHub Desktop.
class MacroCartCommand implements CartCommand {
def commands = []
MacroCartCommand leftShift(CartCommand command) {
commands << command
this
}
void setReceiver(Cart cart) {
commands*.cart = cart
}
def execute() {
commands*.execute()
}
}
def macroCommand = new MacroCartCommand()
macroCommand << command1 << command2 << command3
def newCart = new Cart()
macroCommand.receiver = newCart
macroCommand.execute()
assert newCart.items.keySet() == ['Item2'] as Set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment