chalup/advent-swift

Use guard statement to avoid forced unwrapping and return early

ayoy opened this issue · 0 comments

ayoy commented

let head = Set(wires.first!)

func wiresCrossings(wires: [[Point]]) -> Set<Point> {
    guard let firstWire = wires.first else {
        return []
    }

    let head = Set(firstWire)
    return wires.dropFirst().reduce(head) { $0.intersection($1) }
}