Collection
protocol Collection : Sequence
-
Returns the longest possible subsequences of the collection, in order, that don’t contain
element
.Declaration
Swift
public func split(on element: Iterator.Element) -> [SubSequence]
Parameters
element
Splitter.
Return Value
An array of subsequences, split from this collection’s elements.
-
Split on any of the given elements.
Declaration
Swift
public func split<C: Collection>(oneOf elements: C)-> [SubSequence] where C.Iterator.Element == Iterator.Element
Parameters
elements
Splitters.
Return Value
An array of subsequences, split from this collection’s elements.
-
chunks(of: n)
splits a list into length-n pieces. The last piece will be shorter ifn
does not evenly divide the length of the list. If n <= 0, `chunksOf(n) returns an infinite list of empty lists. For example:[-7, 5, 9].chunks(of: -1) = []
Note that
[].chunksOf(n)
is[]
, not[[]]
. This is intentional, and is consistent with a recursive definition of chunksOf; it satisfies the property thatxs.chunks(of: n) + ys.chunks(of: n) == (xs + ys).chunks(of: n)
whenever n evenly divides the length of xs.
Declaration
Swift
public func chunks(of size: Int) -> [SubSequence]
Parameters
size
Size of chunk.
Return Value
Array of length-size pieces.