Skip to content

Instantly share code, notes, and snippets.

@stevehebert
Last active October 23, 2020 18:17
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 stevehebert/d8d431eb98e1b1ae6ae99b2dd72dbc1d to your computer and use it in GitHub Desktop.
Save stevehebert/d8d431eb98e1b1ae6ae99b2dd72dbc1d to your computer and use it in GitHub Desktop.
// given a set of functions defined on our interface
type Functions interface {
RecordDelivery(x Order) Order
ApplyTotals(x Order) Order
NotifyMember(x Order) Order
}
// we can now create a function new function that composes these
// into a new ordering
func ComposeDeliveryFunction(functionSet Functions) func(x int) int {
// now we can compose a new function using our building block of functions
return func(x int) int {
return functionSet.NotifyMember(functionSet.ApplyTotals(functionSet.RecordDelivery(x)))
}
// now we have a discrete function that can be called to Perform Delivery in a uniform manner
PerformDelivery := ComposeDeliveryFunction(functionSet)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment