Skip to content

Instantly share code, notes, and snippets.

@lukesutton
Created November 21, 2016 23:03
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 lukesutton/6e471bfb82c16fd0f859152aeb2ec9bc to your computer and use it in GitHub Desktop.
Save lukesutton/6e471bfb82c16fd0f859152aeb2ec9bc to your computer and use it in GitHub Desktop.
enum ActionResult<R> {
case success(R)
case error(Error)
}
struct Action<Context, Input, Result> {
let run: (Context, Input) -> ActionResult<Result>
}
func + <Context, Input, ResultA, ResultB>(lhs: Action<Context, Input, ResultA>, rhs: Action<Context, ResultA, ResultB>) -> Action<Context, Input, ResultB> {
return Action { context, input in
switch lhs.run(context, input) {
case let .success(result): return rhs.run(context, result)
case let .error(error): return .error(error)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment