Avatar
うん、単に if case let _? = optionalInt { ... } を↓に挙げなかったよって言ってるだけかと。 let array: [Int?] = [1, 2, nil] // Match using an optional pattern. for case let element? in array { ... } // Match using an enum case pattern. for case let .some(element) in array { ... } let optionalInt: Int? = 0 // Match using an optional pattern. if case let unwrapped? = optionalInt { ... } // Match using an enum case pattern. if case let .some(unwrapped) = optionalInt { ... } // Match using optional binding. if let unwrapped = optionalInt { ... } // Match against .some using an optional pattern switch optionalInt { case let unwrapped?: print() case nil: print() } // Match against .some using enum case pattern switch optionalInt { case let .some(unwrapped): print() case nil: print() }
3:31 AM
なんで for element in sequenc? が less disruptive なのにそれを採用しなかったんだろう??
3:33 AM
A terminating ? sigil here can be thought of as bringing the for loop into the optional chain with the sequence and mirrors the force-unwrapping case (sequence!). On the other hand, this alternative sytactically has a lot in common with optional patterns that are used as sugar for pattern-matching .some(value). The following examples are equivalent per statement type:
最初、これ↑の On the other hand 以降で反対意見述べてんのかと思ったけど、これって単に前半で Optional chaning や Forcen unwrapping との関係を、後半でパターンマッチングとの関係を述べてるだけやんね?
(edited)
3:34 AM
tkrajacic What is your evaluation of the proposal? +1 but with a strong preference for the for element in elements? {…} syntax
3:34 AM
まったく同じ気持ちだ。