Sequence - leacode/SwiftWings GitHub Wiki

Sequence Extensions

Sources

  • Sources/Extensions/Foundation/Sequence/Sequence+Extensions.swift
  • Sources/Extensions/Foundation/Sequence/Sequence+Concurrency.swift

Tests: Tests/Extensions/Sequence

Sequence.unique()

  • 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.

Example

let values = ["a", "b", "a", "c", "b"]
print(values.unique()) // ["a", "b", "c"]

Concurrency Additions

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
⚠️ **GitHub.com Fallback** ⚠️