Returns a sequence formed from repeated lazy applications of next
to a mutable state
.
SDK
- Xcode 8.0+
Framework
- Swift Standard Library
Declaration
Parameters
state
The initial state that will be passed to the closure.
next
A closure that accepts an
inout
state and returns the next element of the sequence.
Return Value
A sequence that yields each successive value from next
.
Discussion
The elements of the sequence are obtained by invoking next
with a mutable state. The same state is passed to all invocations of next
, so subsequent calls will see any mutations made by previous calls. The sequence ends when next
returns nil
. If next
never returns nil
, the sequence is infinite.
This function can be used to replace many instances of Any
that wrap a closure.
Example: