This is a list of the existing standard library and Swift Algorithms operations that are defined for sequences and/or collections, broken down by where they can be implemented with the existing Container design. We'll keep the list updated as we implement these for borrowing sequences, borrowing iterators, and containers in the ContainersPreview module.
BorrowingSequence methods
BorrowingIteratorProtocol methods
Container methods
Consuming only ?
Both sorting and shuffling imply consuming (or copying) the existing sequence
to produce a new version (though shuffled can be implemented with O(n) storage
by shuffling the keys).
Uses sequence as element
split and join both require sequences as the element type, on opposite
sides of the operation. split needs to produce a sequence of sequences, whereas
joined starts with a sequence of sequences.
In-place mutation
†: Swift Algorithms Methods
This is a list of the existing standard library and Swift Algorithms operations that are defined for sequences and/or collections, broken down by where they can be implemented with the existing
Containerdesign. We'll keep the list updated as we implement these for borrowing sequences, borrowing iterators, and containers in theContainersPreviewmodule.BorrowingSequencemethodscontains(_:)/contains(where:)allSatisfy(_:)reduce(_:_:)reduce(into:_:)forEach(_:)elementsEqual(_:)elementsEqual(_:by:)starts(with:)starts(with:by:)lexicographicallyPrecedes(_:)lexicographicallyPrecedes(_:by:)count(where:)BorrowingIteratorProtocolmethodsmap(_:)compactMap(_:)flatMap(_:)filter(_:)compacted()†reductions(_:)†reductions(_:_:)†reductions(into:_:)†prefix(_:)prefix(while:)suffix(_)dropFirst(_:)dropLast(_:)drop(while:)trimming(while:)†trim(while:)†trimmingPrefix(while:)†trimPrefix(while:)†trimmingSuffix(while:)†trimSuffix(while:)†suffix(while:)†enumerated()(result type has tuple element)product(_:_:)† (result type has tuple element)chain(_:_:)† (merges two lifetimes — possible?Container-only?)cycled()†cycled(times:)†striding(by:)†Containermethodsfirst(where:)firstNonNil(_:)†min()max()min(count:)†max(count:)†minAndMax()†randomElement()reversed()(requires bidirectionality)combinations(ofCount:)† (requires O(n) storage for indices)permutations(ofCount:)† (requires O(n) storage for indices)uniquePermutations(ofCount:)† (requires O(n) storage for indices)adjacentPairs()† (result type has tuple element)endOfPrefix(while:)†startOfSuffix(while:)†indexed()†partitioningIndex(where:)†Consuming only ?
Both sorting and shuffling imply consuming (or copying) the existing sequence
to produce a new version (though
shuffledcan be implemented with O(n) storageby shuffling the keys).
sorted()shuffled()keyed(by:)†keyed(by:resolvingConflictsWith:)†grouped(by:)†partitioned(by:)†uniqued()†uniqued(on:)†randomSample(count:)†randomStableSample(count:)†Uses sequence as element
splitandjoinboth require sequences as the element type, on oppositesides of the operation.
splitneeds to produce a sequence of sequences, whereasjoinedstarts with a sequence of sequences.split(maxSplits:omittingEmptySubsequences:whereSeparator:)split(separator:maxSplits:omittingEmptySubsequences:)interspersed(with:)†joined()joined(separator:)joined(by:)†windows(ofCount:)†chunks(ofCount:)†evenlyChunked(in:)†chunked(by:)†chunked(on:)†In-place mutation
sort()stablePartition(by:)†stablePartition(subrange:by:)†partition(by:)†partition(subrange:by:)†rotate(toStartAt:)†rotate(subrange:toStartAt:)†reverse(subrange:)††: Swift Algorithms Methods