Accepted: SE-199 – Add `toggle` to `Bool`


(Ben Cohen) #1

The review of SE-199 has ended, and the proposal has been accepted as-is. There was some discussion during the review of alternative names, but the team felt that toggle was the best one offered.

During the review, there was some discussion as to whether this kind of helper method belonged in the standard library. The core team sees the following motivations for its addition:

  • commonality: the team felt that the need to toggle a nested boolean is a common one across multiple different problem domains
  • readability: the addition of this command can significantly improve readability, especially as was seen in the example of toggling a boolean in a type held as a value in a dictionary
  • consistency: while reproducing the method in user code is fairly trivial, it is good to have a consistent way of doing this across all swift codebases, rather than having multiple variants
  • correctness: there is a correctness risk when the same long path needs to appear on both sides (especially when subscripts are involved), which this method would avoid
  • performance: this didn’t come up during the review, but a mutating member operation will be more efficient (requiring only one subscript lookup) once we have the co-routine-based accessors, planned for a future release

The core team would welcome further proposals to fill in gaps like this in the standard library.


SE-0199: Adding toggle method to Bool
Adding toggle to Bool
Guarded closures
(Ben Cohen) #2

5 posts were split to a new topic: Add toggle to Bool: spin-off discussion