Skip to content

Instantly share code, notes, and snippets.

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