Collection (ext)
You’re viewing third-party extensions to Collection
, a protocol from the Swift standard library.
You can also read the documentation forCollection
itself.
extension Collection
You’re viewing third-party extensions to Collection
, a protocol from the Swift standard library.
You can also read the documentation forCollection
itself.
extension Collection
protocol Collection<Element> : Sequence
A sequence whose elements can be traversed multiple times, nondestructively, and accessed by an indexed subscript.
import Algorithms
Swift Algorithms is an open-source package of sequence and collection algorithms, along with their related types.
func adjacentPairs() -> AdjacentPairsCollection<Self>
Returns a collection of overlapping adjacent pairs of the elements of this collection.
func chunked(by belongInSameGroup: (Element, Element) throws -> Bool) rethrows -> [SubSequence]
Returns a collection of subsequences of this collection, chunked by the given predicate.
func chunked<Subject>(on projection: (Element) throws -> Subject) rethrows -> [(Subject, SubSequence)] where Subject : Equatable
Returns a collection of subsequences of this collection, chunked by grouping elements that project to equal values.
func chunks(ofCount count: Int) -> ChunksOfCountCollection<Self>
Returns a collection of subsequences, each with up to the specified length.
func combinations(ofCount k: Int) -> CombinationsSequence<Self>
Returns a collection of combinations of this collection’s elements, with each combination having the specified number of elements.
func combinations<R>(ofCount kRange: R) -> CombinationsSequence<Self> where R : RangeExpression, R.Bound == Int
Returns a collection of combinations of this collection’s elements, with each combination having the specified number of elements.
func compacted<Unwrapped>() -> CompactedCollection<Self, Unwrapped> where Self.Element == Unwrapped?
Returns a new Collection
that iterates over every non-nil element from the original Collection
.
func cycled() -> CycledSequence<Self>
Returns a sequence that repeats the elements of this collection forever.
func cycled(times: Int) -> CycledTimesCollection<Self>
Returns a sequence that repeats the elements of this collection the specified number of times.
func endOfPrefix(while predicate: (Element) throws -> Bool) rethrows -> Index
Returns the exclusive upper bound of the prefix of elements that satisfy the predicate.
func evenlyChunked(in count: Int) -> EvenlyChunkedCollection<Self>
Returns a collection of evenly divided consecutive subsequences of this collection.
func indexed() -> IndexedCollection<Self>
Returns a collection of pairs (i, x), where i represents an index of the collection, and x represents an element.
func max(count: Int, sortedBy areInIncreasingOrder: (Element, Element) throws -> Bool) rethrows -> [Element]
Returns the largest elements of this collection, as sorted by the given predicate.
func min(count: Int, sortedBy areInIncreasingOrder: (Element, Element) throws -> Bool) rethrows -> [Element]
Returns the smallest elements of this collection, as sorted by the given predicate.
func partitioned(by predicate: (Element) throws -> Bool) rethrows -> (falseElements: [Element], trueElements: [Element])
Returns two arrays containing, in order, the elements of the collection that do and don’t satisfy the given predicate.
func partitioningIndex(where belongsInSecondPartition: (Element) throws -> Bool) rethrows -> Index
Returns the start index of the partition of a collection that matches the given predicate.
func permutations(ofCount k: Int? = nil) -> PermutationsSequence<Self>
Returns a collection of the permutations of this collection of the specified length.
func permutations<R>(ofCount kRange: R) -> PermutationsSequence<Self> where R : RangeExpression, R.Bound == Int
Returns a collection of the permutations of this collection with lengths in the specified range.
func randomSample(count k: Int) -> [Element]
Randomly selects the specified number of elements from this collection.
func randomSample<G>(count k: Int, using rng: inout G) -> [Element] where G : RandomNumberGenerator
Randomly selects the specified number of elements from this collection.
func randomStableSample(count k: Int) -> [Element]
Randomly selects the specified number of elements from this collection, maintaining their relative order.
func randomStableSample<G>(count k: Int, using rng: inout G) -> [Element] where G : RandomNumberGenerator
Randomly selects the specified number of elements from this collection, maintaining their relative order.
func striding(by step: Int) -> StridingCollection<Self>
Returns a sequence stepping through the elements every step
starting at the first value. Any remainders of the stride will be trimmed.
func trimmingPrefix(while predicate: (Element) throws -> Bool) rethrows -> SubSequence
Returns a SubSequence
formed by discarding all elements at the start of the collection which satisfy the given predicate.
func windows(ofCount count: Int) -> WindowsOfCountCollection<Self>
Returns a collection of all the overlapping slices of a given size.
protocol RangeReplaceableCollection<Element> : Collection where Self.SubSequence : RangeReplaceableCollection
A collection that supports replacement of an arbitrary subrange of elements with the elements of another collection.
mutating func trimPrefix(while predicate: (Element) throws -> Bool) rethrows
Mutates a Collection
by discarding all elements at the start of it which satisfy the given predicate.
mutating func trimPrefix(while predicate: (Element) throws -> Bool) rethrows
Mutates a Collection
by discarding all elements at the start of it which satisfy the given predicate.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
func uniquePermutations(ofCount k: Int? = nil) -> UniquePermutationsSequence<Self>
Returns a sequence of the unique permutations of this sequence of the specified length.
func uniquePermutations<R>(ofCount kRange: R) -> UniquePermutationsSequence<Self> where R : RangeExpression, R.Bound == Int
Returns a collection of the unique permutations of this sequence with lengths in the specified range.
protocol Comparable : Equatable
A type that can be compared using the relational operators <
, <=
, >=
, and >
.
func max(count: Int) -> [Element]
Returns the largest elements of this collection.
func min(count: Int) -> [Element]
Returns the smallest elements of this collection.
func joined<Separator>(by separator: Separator) -> JoinedByCollection<Self, Separator> where Separator : Collection, Separator.Element == Self.Element.Element
Returns the concatenation of the elements in this collection of collections, inserting the given separator between each collection.
func joined(by separator: Element.Element) -> JoinedByCollection<Self, CollectionOfOne<Element.Element>>
Returns the concatenation of the elements in this collection of collections, inserting the given separator between each collection.