LazyMapSequence

struct LazyMapSequence

A Sequence whose elements consist of those in a Base Sequence passed through a transform function returning Element. These elements are computed lazily, each time they're read, by calling the transform function on a base element.

Inheritance LazySequenceProtocol
Associated Types
public typealias Elements = LazyMapSequence<Base, Element>
  • See also: elements
Nested Types LazyMapSequence.Iterator

Instance Variables

var base Required

Declaration

var base: Base.Iterator
var lazy Required

Declaration

var lazy: LazySequence<Self.Elements>
var underestimatedCount Required

A value less than or equal to the number of elements in the sequence, calculated nondestructively.

The default implementation returns 0. If you provide your own implementation, make sure to compute the value nondestructively.

Complexity: O(1), except if the sequence also conforms to Collection. In this case, see the documentation of Collection.underestimatedCount.

Declaration

var underestimatedCount: Int

Instance Methods

func compactMap(_ transform: @escaping (Self.Elements.Element) -> ElementOfResult?) -> LazyMapSequence<LazyFilterSequence<LazyMapSequence<Self.Elements, ElementOfResult?>>, ElementOfResult> Required

Returns the non-nil results of mapping the given transformation over this sequence.

Use this method to receive a sequence of non-optional values when your transformation produces an optional value.

  • Parameter transform: A closure that accepts an element of this sequence as its argument and returns an optional value.

Complexity: O(1)

Declaration

@inlinable public func compactMap<ElementOfResult>(_ transform: @escaping (Self.Elements.Element) -> ElementOfResult?) -> LazyMapSequence<LazyFilterSequence<LazyMapSequence<Self.Elements, ElementOfResult?>>, ElementOfResult>
func drop(while predicate: @escaping (Self.Elements.Element) -> Bool) -> LazyDropWhileSequence<Self.Elements> Required

Returns a lazy sequence that skips any initial elements that satisfy predicate.

  • Parameter predicate: A closure that takes an element of the sequence as its argument and returns true if the element should be skipped or false otherwise. Once predicate returns false it will not be called again.

Declaration

@inlinable public func drop(while predicate: @escaping (Self.Elements.Element) -> Bool) -> LazyDropWhileSequence<Self.Elements>
func filter(_ isIncluded: @escaping (Self.Elements.Element) -> Bool) -> LazyFilterSequence<Self.Elements> Required

Returns the elements of self that satisfy isIncluded.

Note: The elements of the result are computed on-demand, as the result is used. No buffering storage is allocated and each traversal step invokes predicate on one or more underlying elements.

Declaration

@inlinable public func filter(_ isIncluded: @escaping (Self.Elements.Element) -> Bool) -> LazyFilterSequence<Self.Elements>
func flatMap(_ transform: @escaping (Self.Elements.Element) -> SegmentOfResult) -> LazySequence<FlattenSequence<LazyMapSequence<Self.Elements, SegmentOfResult>>> Required

Returns the concatenated results of mapping the given transformation over this sequence.

Use this method to receive a single-level sequence when your transformation produces a sequence or collection for each element. Calling flatMap(_:) on a sequence s is equivalent to calling s.map(transform).joined().

Complexity: O(1)

Declaration

@inlinable public func flatMap<SegmentOfResult>(_ transform: @escaping (Self.Elements.Element) -> SegmentOfResult) -> LazySequence<FlattenSequence<LazyMapSequence<Self.Elements, SegmentOfResult>>> where SegmentOfResult: Sequence
func flatMap(_ transform: @escaping (Self.Elements.Element) -> ElementOfResult?) -> LazyMapSequence<LazyFilterSequence<LazyMapSequence<Self.Elements, ElementOfResult?>>, ElementOfResult> Required

Returns the non-nil results of mapping the given transformation over this sequence.

Use this method to receive a sequence of non-optional values when your transformation produces an optional value.

  • Parameter transform: A closure that accepts an element of this sequence as its argument and returns an optional value.

Complexity: O(1)

Declaration

@available(swift, deprecated: 4.1, renamed: "compactMap(_:)", message: "Please use compactMap(_:) for the case where closure returns an optional value") public func flatMap<ElementOfResult>(_ transform: @escaping (Self.Elements.Element) -> ElementOfResult?) -> LazyMapSequence<LazyFilterSequence<LazyMapSequence<Self.Elements, ElementOfResult?>>, ElementOfResult>
func makeIterator() -> LazyMapSequence<Base, Element>.Iterator Required

Returns an iterator over the elements of this sequence.

Complexity: O(1).

Declaration

@inlinable public func makeIterator() -> LazyMapSequence<Base, Element>.Iterator
func map(_ transform: @escaping (Element) -> ElementOfResult) -> LazyMapSequence<Base, ElementOfResult> Required

Declaration

@available(swift 5) @inlinable public func map<ElementOfResult>(_ transform: @escaping (Element) -> ElementOfResult) -> LazyMapSequence<Base, ElementOfResult>
func map(_ transform: @escaping (Self.Element) -> U) -> LazyMapSequence<Self.Elements, U> Required

Returns a LazyMapSequence over this Sequence. The elements of the result are computed lazily, each time they are read, by calling transform function on a base element.

Declaration

@inlinable public func map<U>(_ transform: @escaping (Self.Element) -> U) -> LazyMapSequence<Self.Elements, U>
func prefix(while predicate: @escaping (Self.Elements.Element) -> Bool) -> LazyPrefixWhileSequence<Self.Elements> Required

Returns a lazy sequence of the initial consecutive elements that satisfy predicate.

  • Parameter predicate: A closure that takes an element of the sequence as its argument and returns true if the element should be included or false otherwise. Once predicate returns false it will not be called again.

Declaration

@inlinable public func prefix(while predicate: @escaping (Self.Elements.Element) -> Bool) -> LazyPrefixWhileSequence<Self.Elements>