Summary
Sequence provides iteration. It allows you to create an iterator, but there are no guarantees about whether the sequence is single-pass (e.g. reading from standard input) or multi-pass (iterating over an array).
Types
IteratorProtocol
1 | public protocol IteratorProtocol { |
Sequence
1 | public protocol Sequence { |
DropFirstSequence, PrefixSequence, DropWhileSequence
在dropFirst,prefix, drop(while:) 方法中,返回的并非为Array或者Sequence类型,而是返回了对应的XXSequence struct 类型。看注释上说时可以lazily consume. 这几类Sequence有些类似Box/Wrapper Sequence.
1 | /// A sequence that lazily consumes and drops `n` elements from an underlying |
Functions
suffix(_ maxLength: Int)
1 | /// Returns a subsequence, up to the given maximum length, containing the |
dropLast(_ k: Int = 1) -> [Element]
1 | /// Returns a sequence containing all but the given number of final |
elementsEqual
1 | extension Sequence where Element: Equatable { |
flatMap
1 | extension Sequence { |
compactMap
1 | extension Sequence { |