Skip to content

Instantly share code, notes, and snippets.

@chriseidhof
Created June 9, 2015 16:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriseidhof/c562e83df5e79cecf161 to your computer and use it in GitHub Desktop.
Save chriseidhof/c562e83df5e79cecf161 to your computer and use it in GitHub Desktop.
Result
enum Result<A,B> {
case Left(A)
case Right(B)
}
extension Result {
func reduce<R>(f: A -> R, g: B -> R) -> R {
switch self {
case .Left(let a): return f(a)
case .Right(let b): return g(b)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment