Skip to content

Commit

Permalink
use Dictionary(grouping:by:) init to simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
tejassharma96 committed Nov 19, 2024
1 parent 24aa439 commit 8a9d798
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions Sources/Yams/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,8 @@ private extension Parser {
}

private func checkDuplicates(mappingKeys: [Node]) throws {
var duplicates: [Node: [Node]] = [:]
for key in mappingKeys {
if duplicates.keys.contains(key) {
duplicates[key]?.append(key)
} else {
duplicates[key] = [key]
}
}
duplicates = duplicates.filter { $1.count > 1 }
let duplicates: [Node: [Node]] = Dictionary(grouping: mappingKeys) { $0 }
.filter { $1.count > 1 }
guard duplicates.isEmpty else {
throw YamlError.duplicatedKeysInMapping(duplicates: duplicates, yaml: yaml)
}
Expand Down

0 comments on commit 8a9d798

Please sign in to comment.