Sequence - leacode/SwiftWings GitHub Wiki
Sources
Sources/Extensions/Foundation/Sequence/Sequence+Extensions.swiftSources/Extensions/Foundation/Sequence/Sequence+Concurrency.swift
Tests: Tests/Extensions/Sequence
- Available when
Element: Hashable. - Iterates through the sequence while tracking previously-seen values in a
Set, ensuring only the first occurrence of each element is kept. - Maintains the order of the original sequence.
let values = ["a", "b", "a", "c", "b"]
print(values.unique()) // ["a", "b", "c"]SwiftWings' new async helpers are inspired by CollectionConcurrencyKit, which popularized asyncMap and concurrentMap patterns for sequences.
| API | Description | Tests |
|---|---|---|
Sequence.asyncMap(_:) |
Sequentially awaits each element (mirroring the examples from John Sundell's guide). | Sequence_ConcurrencyTests.testAsyncMapPreservesOrder |
Sequence.concurrentMap(_:) |
Uses withThrowingTaskGroup to maintain order while executing tasks concurrently, similar to CollectionConcurrencyKit's approach. |
Sequence_ConcurrencyTests.testConcurrentMapPreservesOrder |
Sequence.asyncForEach(_:), Sequence.concurrentForEach(_:)
|
Await/parallel forEach helpers for async workflows. |
Sequence_ConcurrencyTests.testConcurrentForEachExecutesAllElements |