Skip to content

Commit

Permalink
added map to response
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyapuchka committed Jan 2, 2016
1 parent 3feb154 commit 199c276
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions SwiftNetworking/APIResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ public struct APIResponseOf<ResultType: APIResponseDecodable>: APIResponse {
return httpResponse?.MIMEType.flatMap {HTTPContentType(rawValue: $0)}
}
}

public func map<T>(f: ResultType -> T) -> APIResponseOf<T> {
return flatMap(f)
}

public func mapError<E: ErrorType>(f: ErrorType -> E) -> APIResponseOf {
return flatMapError(f)
}

public func flatMap<T>(f: ResultType -> T?) -> APIResponseOf<T> {
var response = APIResponseOf<T>(request: originalRequest, data: data, httpResponse: httpResponse, error: error)
response.result = result.flatMap(f)
return response
}

public func flatMapError<E: ErrorType>(f: ErrorType -> E?) -> APIResponseOf {
var response = APIResponseOf(request: originalRequest, data: data, httpResponse: httpResponse, error: error.flatMap(f) ?? error)
response.result = result
return response
}

}

public struct None: APIResponseDecodable {
Expand Down
4 changes: 4 additions & 0 deletions SwiftNetworking/JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ extension Optional {
return self as? Swift.Int
}

public var Bool: Swift.Bool? {
return self as? Swift.Bool
}

public var Array: [JSONDictionary]? {
return self as? [JSONDictionary]
}
Expand Down

0 comments on commit 199c276

Please sign in to comment.