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 |
|
Nested Types | LazyMapSequence.Iterator |
Instance Variables
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 ofCollection.underestimatedCount
.
Declaration
var
underestimatedCount
:
Int
Instance Methods
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
>
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 orfalse
otherwise. Oncepredicate
returnsfalse
it will not be called again.
Declaration
@
inlinable
public
func
drop
(
while
predicate
: @
escaping
(
Self
.
Elements
.
Element
) -
>
Bool
) -
>
LazyDropWhileSequence
<
Self
.
Elements
>
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
>
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
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
>
Returns an iterator over the elements of this sequence.
Complexity: O(1).
Declaration
@
inlinable
public
func
makeIterator
() -
>
LazyMapSequence
<
Base
,
Element
>
.
Iterator
Declaration
@
available
(
swift
5
) @
inlinable
public
func
map
<
ElementOfResult
>
(
_
transform
: @
escaping
(
Element
) -
>
ElementOfResult
) -
>
LazyMapSequence
<
Base
,
ElementOfResult
>
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
>
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 orfalse
otherwise. Oncepredicate
returnsfalse
it will not be called again.
Declaration
@
inlinable
public
func
prefix
(
while
predicate
: @
escaping
(
Self
.
Elements
.
Element
) -
>
Bool
) -
>
LazyPrefixWhileSequence
<
Self
.
Elements
>
elements