Skip to content

Commit

Permalink
Unbox array with formatter uses a for-in loop rather than a mapping f…
Browse files Browse the repository at this point in the history
…unction to return early when invalid values encountered when not allowed
  • Loading branch information
mikezs committed Jul 1, 2016
1 parent d6c338e commit f813026
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions Sources/Unbox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -716,18 +716,17 @@ public class Unboxer {
if allowInvalidElements {
return array.flatMap({ formatter.formatUnboxedValue($0) })
} else {
var invalidElement = false
var formattedArray = [T]()

let mapping = array.flatMap({ (value) -> T? in
if let formattedValue = formatter.formatUnboxedValue(value) {
return formattedValue
for value in array {
guard let formattedValue = formatter.formatUnboxedValue(value) else {
return nil
}

invalidElement = true
return nil
})
formattedArray.append(formattedValue)
}

return invalidElement ? nil : mapping
return formattedArray
}
})
}
Expand Down

0 comments on commit f813026

Please sign in to comment.