Use first(where:) instead of filter().first

This commit is contained in:
Damiano Galassi committed 2020-02-04 14:03:30 +01:00
1 parent 6c29faf8f4
commit 93e82651ea
6 files changed
+11 -14

No files matched your search

+3 -5
View File
@@ -38,7 +38,7 @@ private struct SquaredTVArtJsonApi {
let caption: String?
func toRemoteImage() -> Artwork {
let thumbURL = alt_sizes.filter { $0.width > 200 && $0.width < 400 }.first?.url ?? original_size.url
let thumbURL = alt_sizes.first { $0.width > 200 && $0.width < 400 }?.url ?? original_size.url
return Artwork(url: original_size.url, thumbURL: thumbURL, service: "Squared TV Art", type: .season, size: .square)
}
}
@@ -208,16 +208,14 @@ private struct SquaredTVArtHTMLScraper {
}
private func parse(info: [Substring], type: String) -> Int? {
let filtered = info.filter { $0.hasPrefix(type) }
if let seriesID = filtered.first {
if let seriesID = info.first(where: { $0.hasPrefix(type) }) {
return Int(String(seriesID).replacingOccurrences(of: type, with: ""))
}
return nil
}
private func parseString(info: [Substring], type: String) -> String? {
let filtered = info.filter { $0.hasPrefix(type) }
if let seriesID = filtered.first {
if let seriesID = info.first(where: { $0.hasPrefix(type) }) {
return String(seriesID).replacingOccurrences(of: type, with: "")
}
return nil