You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Finish sub-page documentation updates
Some of these pages could use introductions, but the current state is
ready for publication.
* Add SPI yaml file for building docs
Copy file name to clipboardExpand all lines: Sources/Algorithms/Documentation.docc/Algorithms.md
+19-2Lines changed: 19 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,25 @@ along with their related types.
5
5
6
6
## Overview
7
7
8
-
This library adds a variety of extended operations to the Swift standard library's
9
-
`Sequence` and `Collection` protocols, via extension methods and global functions.
8
+
The Algorithms package provides a variety of sequence and collection operations, letting you cycle over a collection's elements, find combinations and permutations, create a random sample, and more.
9
+
10
+
For example, the package includes a group of "chunking" methods, each of which breaks a collection into consecutive subsequences. One version tests adjacent elements to find the breaking point between chunks — you can use it to quickly separate an array into ascending runs:
11
+
12
+
```swift
13
+
let numbers = [10, 20, 30, 10, 40, 40, 10, 20]
14
+
let chunks = numbers.chunked(by: { $0<=$1 })
15
+
// [[10, 20, 30], [10, 40, 40], [10, 20]]
16
+
```
17
+
18
+
Another version looks for a change in the transformation of each successive value. You can use that to separate a list of names into groups by the first character:
19
+
20
+
```swift
21
+
let names = ["Cassie", "Chloe", "Jasmine", "Jordan", "Taylor"]
Copy file name to clipboardExpand all lines: Sources/Algorithms/Documentation.docc/Chunking.md
+15-2Lines changed: 15 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,17 @@ Break collections into consecutive chunks by length, count, or based on closure-
4
4
5
5
## Overview
6
6
7
+
_Chunking_ is the process of breaking a collection into consecutive subsequences, without dropping or duplicating any of the collection's elements. After chunking a collection, joining the resulting subsequences produces the original collection of elements, unlike _splitting_, which consumes the separator element(s).
8
+
9
+
```swift
10
+
let names = ["Ji-sun", "Jin-su", "Min-jae", "Young-ho"]
0 commit comments