Created
November 30, 2015 00:02
-
-
Save sam-w/4673e6a67b16769ab05a to your computer and use it in GitHub Desktop.
Reducing over ResultType<Value: CollectionType, Error>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension ResultType where Value: CollectionType { | |
public func reduce<U>(initial: U, @noescape combine: (U, Value.Generator.Element) -> Result<U, Error>) -> Result<U, Error> { | |
return analysis( | |
ifSuccess: { | |
$0.reduce(.Success(initial)) { (acc, item) in | |
return acc.flatMap { | |
combine($0, item) | |
} | |
} | |
}, | |
ifFailure: Result<U, Error>.Failure) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment