func adjacentPairs() -> AdjacentPairsCollection<Self>
Returns a collection of overlapping adjacent pairs of the elements of this collection.
func chunked(by: (Element, Element) throws -> Bool) rethrows -> [SubSequence]
Returns a collection of subsequences of this collection, chunked by the given predicate.
func chunked<Subject>(on: (Element) throws -> Subject) rethrows -> [(Subject, SubSequence)]
Returns a collection of subsequences of this collection, chunked by grouping elements that project to equal values.
func chunks(ofCount: Int) -> ChunksOfCountCollection<Self>
Returns a collection of subsequences, each with up to the specified length.
func combinations(ofCount: Int) -> CombinationsSequence<Self>
Returns a collection of combinations of this collection’s elements, with each combination having the specified number of elements.
func compacted<Unwrapped>() -> CompactedSequence<Self, Unwrapped>
Returns a new Sequence
that iterates over every non-nil element from the original Sequence
.
func compacted<Unwrapped>() -> CompactedCollection<Self, 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: (Element) throws -> Bool) rethrows -> Index
Returns the exclusive upper bound of the prefix of elements that satisfy the predicate.
func evenlyChunked(in: Int) -> EvenlyChunkedCollection<Self>
Returns a collection of evenly divided consecutive subsequences of this collection.
func firstNonNil<Result>((Element) throws -> Result?) rethrows -> Result?
Returns the first non-nil
result obtained from applying the given transformation to the elements of the sequence.
func flatten<Value>(on: EventLoop) -> EventLoopFuture<[Value]>
Converts a collection of EventLoopFuture
s to an EventLoopFuture
that wraps an array with the future values.
func grouped<GroupKey>(by: (Element) throws -> GroupKey) rethrows -> [GroupKey : [Element]]
Groups up elements of self
into a new Dictionary, whose values are Arrays of grouped elements, each keyed by the group key returned by the given closure.
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 interspersed(with: Element) -> InterspersedSequence<Self>
Returns a sequence containing elements of this sequence with the given separator inserted in between each element.
func keyed<Key>(by: (Element) throws -> Key) rethrows -> [Key : Element]
Creates a new Dictionary from the elements of self
, keyed by the results returned by the given keyForValue
closure.
func keyed<Key>(by: (Element) throws -> Key, resolvingConflictsWith: (Key, Element, Element) throws -> Element) rethrows -> [Key : Element]
Creates a new Dictionary from the elements of self
, keyed by the results returned by the given keyForValue
closure. As the dictionary is built, the initializer calls the resolve
closure with the current and new values for any duplicate keys. Pass a closure as resolve
that returns the value to use in the resulting dictionary: The closure can choose between the two values, combine them to produce a new value, or even throw an error.
func max(count: Int, sortedBy: (Element, Element) throws -> Bool) rethrows -> [Element]
Returns the largest elements of this collection, as sorted by the given predicate.
func min(count: Int, sortedBy: (Element, Element) throws -> Bool) rethrows -> [Element]
Returns the smallest elements of this collection, as sorted by the given predicate.
func minAndMax(by: (Element, Element) throws -> Bool) rethrows -> (min: Element, max: Element)?
Returns both the minimum and maximum elements in the sequence, using the given predicate as the comparison between elements.
func partitioned(by: (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: (Element) throws -> Bool) rethrows -> Index
Returns the start index of the partition of a collection that matches the given predicate.
func permutations(ofCount: Int?) -> PermutationsSequence<Self>
Returns a collection of the permutations of this collection of the specified length.
func randomSample(count: Int) -> [Element]
Randomly selects the specified number of elements from this collection.
func randomSample<G>(count: Int, using: inout G) -> [Element]
Randomly selects the specified number of elements from this sequence.
func randomSample<G>(count: Int, using: inout G) -> [Element]
Randomly selects the specified number of elements from this collection.
func randomStableSample(count: Int) -> [Element]
Randomly selects the specified number of elements from this collection, maintaining their relative order.
func randomStableSample<G>(count: Int, using: inout G) -> [Element]
Randomly selects the specified number of elements from this collection, maintaining their relative order.
func reductions((Element, Element) throws -> Element) rethrows -> [Element]
Returns an array containing the accumulated results of combining the elements of the sequence using the given closure.
func reductions<Result>(Result, (Result, Element) throws -> Result) rethrows -> [Result]
Returns an array containing the accumulated results of combining the elements of the sequence using the given closure.
func reductions<Result>(into: Result, (inout Result, Element) throws -> Void) rethrows -> [Result]
Returns an array containing the accumulated results of combining the elements of the sequence using the given closure.
func sequencedFlatMapEach(on: EventLoop, @escaping (_ element: Element) -> EventLoopFuture<Void>) -> EventLoopFuture<Void>
An overload of sequencedFlatMapEach(on:_:)
which returns a Void
future instead of [Void]
when the result type of the transform closure is Void
.
func sequencedFlatMapEachCompact<Result>(on: EventLoop, @escaping (_ element: Element) -> EventLoopFuture<Result?>) -> EventLoopFuture<[Result]>
Variant of sequencedFlatMapEach(on:_:)
which provides compactMap()
semantics by allowing result values to be nil
. Such results are not included in the output array.
func startOfSuffix(while: (Element) throws -> Bool) rethrows -> Index
Returns the inclusive lower bound of the suffix of elements that satisfy the predicate.
func striding(by: 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 suffix(while: (Element) throws -> Bool) rethrows -> SubSequence
Returns a subsequence containing the elements from the end until predicate
returns false
and skipping the remaining elements.
func trimming(while: (Element) throws -> Bool) rethrows -> SubSequence
Returns a SubSequence
formed by discarding all elements at the start and end of the collection which satisfy the given predicate.
func trimmingSuffix(while: (Element) throws -> Bool) rethrows -> SubSequence
Returns a SubSequence
formed by discarding all elements at the end of the collection which satisfy the given predicate.
func uniqued<Subject>(on: (Element) throws -> Subject) rethrows -> [Element]
Returns an array with the unique elements of this sequence (as determined by the given projection), in the order of the first occurrence of each unique element.
func windows(ofCount: Int) -> WindowsOfCountCollection<Self>
Returns a collection of all the overlapping slices of a given size.