Skip to content

Commit f02086f

Browse files
authored
Merge pull request #71277 from jmschonfeld/se-0270-changelog
Update changelog for SE-0270
2 parents c734975 + 9d2e191 commit f02086f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,35 @@
6464
\_SwiftConcurrencyShims used to declare the `exit` function, even though it
6565
might not be available. The declaration has been removed, and must be imported
6666
from the appropriate C library module (e.g. Darwin or SwiftGlibc)
67+
68+
* [SE-0270][]:
69+
70+
The Standard Library now provides APIs for performing collection operations
71+
over noncontiguous elements. For example:
72+
73+
```swift
74+
var numbers = Array(1...15)
75+
76+
// Find the indices of all the even numbers
77+
let indicesOfEvens = numbers.indices(where: { $0.isMultiple(of: 2) })
78+
79+
// Perform an operation with just the even numbers
80+
let sumOfEvens = numbers[indicesOfEvens].reduce(0, +)
81+
// sumOfEvens == 56
82+
83+
// You can gather the even numbers at the beginning
84+
let rangeOfEvens = numbers.moveSubranges(indicesOfEvens, to: numbers.startIndex)
85+
// numbers == [2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15]
86+
// numbers[rangeOfEvens] == [2, 4, 6, 8, 10, 12, 14]
87+
```
88+
89+
The standard library now provides a new `indices(where:)` function which creates
90+
a `RangeSet` - a new type representing a set of discontiguous indices. `RangeSet`
91+
is generic over its index type and can be used to execute operations over
92+
noncontiguous indices such as collecting, moving, or removing elements from a
93+
collection. Additionally, `RangeSet` is generic over any `Comparable` collection
94+
index and can be used to represent a selection of items in a list or a refinement
95+
of a filter or search result.
6796

6897
## Swift 5.10
6998

0 commit comments

Comments
 (0)