Skip to content

Instantly share code, notes, and snippets.

@AlexanderNey
Last active August 29, 2015 14:23
Show Gist options
  • Save AlexanderNey/c076f7a0f60b7be11074 to your computer and use it in GitHub Desktop.
Save AlexanderNey/c076f7a0f60b7be11074 to your computer and use it in GitHub Desktop.
ARTICLE Function Composing Swift 2.0 - 3
func combine <A,B,C>(first: A throws -> B, _ second: B throws -> C) -> (A throws -> C) {
return { (parameter: A) throws -> C in
let finalResult = try second(first(parameter))
return finalResult
}
}
let data = //... the NSData representing the json
let parseAndValidate = combine(parseJSONFromNSData, validateJSONResponse)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment