Skip to content

Instantly share code, notes, and snippets.

@AlexanderNey
Last active June 15, 2016 12:54
Show Gist options
  • Save AlexanderNey/39845ee92e3b693a2145 to your computer and use it in GitHub Desktop.
Save AlexanderNey/39845ee92e3b693a2145 to your computer and use it in GitHub Desktop.
ARTICLE Function Composing Swift 2.0 - 5
infix operator >>> { precedence 50 associativity left }
public func >>> <A,B,C>(left: A throws -> B, right: B throws -> C) -> (A throws -> C) {
return { (parameter: A) throws -> C in
return try right(left(parameter))
}
}
let data = ...
let handleResponse = parseJSONFromNSData >>> validateJSONResponse >>> unmarshalJSON(Model.self)
let model = try handleResponse(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment