Skip to content

Commit e2cc284

Browse files
committed
Just use SequenceType.flatMap(), remove Array.filterMap() implementation
See http://swiftdoc.org/swift-2/protocol/SequenceType/#func-flatMap
1 parent 6a1c4d9 commit e2cc284

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

ObjectMapper/Core/Mapper.swift

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public final class Mapper<N: Mappable> {
200200
/// Maps an array of JSON dictionary to an array of Mappable objects
201201
public func mapArray(JSONArray: [[String : AnyObject]]) -> [N] {
202202
// map every element in JSON array to type N
203-
return JSONArray.filterMap(map)
203+
return JSONArray.flatMap(map)
204204
}
205205

206206
/// Maps a JSON object to a dictionary of Mappable objects if it is a JSON dictionary of dictionaries, or returns nil.
@@ -323,20 +323,6 @@ public final class Mapper<N: Mappable> {
323323
}
324324
}
325325

326-
extension Array {
327-
internal func filterMap<U>(@noescape f: Element -> U?) -> [U] {
328-
var mapped = [U]()
329-
330-
for value in self {
331-
if let newValue = f(value) {
332-
mapped.append(newValue)
333-
}
334-
}
335-
336-
return mapped
337-
}
338-
}
339-
340326
extension Dictionary {
341327
internal func map<K: Hashable, V>(@noescape f: Element -> (K, V)) -> [K : V] {
342328
var mapped = [K : V]()

ObjectMapper/Core/Operators.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public func <- <T: TransformType>(inout left: [String: T.Object]!, right: (Map,
203203

204204
private func fromJSONArrayWithTransform<T: TransformType>(input: AnyObject?, transform: T) -> [T.Object] {
205205
if let values = input as? [AnyObject] {
206-
return values.filterMap { value in
206+
return values.flatMap { value in
207207
return transform.transformFromJSON(value)
208208
}
209209
} else {
@@ -222,7 +222,7 @@ private func fromJSONDictionaryWithTransform<T: TransformType>(input: AnyObject?
222222
}
223223

224224
private func toJSONArrayWithTransform<T: TransformType>(input: [T.Object]?, transform: T) -> [T.JSON]? {
225-
return input?.filterMap { value in
225+
return input?.flatMap { value in
226226
return transform.transformToJSON(value)
227227
}
228228
}

0 commit comments

Comments
 (0)