On this page
ControlNotificationStream.prefix(while:)
- Declared in
- ControlNotificationStream
- Package
- libtmux-swift
- prefix(while:) ( while : (Self.Element) async -> Bool ) AsyncPrefixWhileSequence<Self>
-
Returns an asynchronous sequence, containing the initial, consecutive elements of the base sequence that satisfy the given predicate.
Use
prefix(while:)to produce values while elements from the base sequence meet a condition you specify. The modified sequence ends when the predicate closure returnsfalse.In this example, an asynchronous sequence called
CounterproducesIntvalues from1to10. Theprefix(while:)method causes the modified sequence to pass along values so long as they aren’t divisible by2and3. Upon reaching6, the sequence ends:let stream = Counter(howHigh: 10) .prefix { $0 % 2 != 0 || $0 % 3 != 0 } for try await number in stream { print(number, terminator: " ") } // Prints "1 2 3 4 5 "
- Parameter predicate: A closure that takes an element as a parameter and returns a Boolean value indicating whether the element should be included in the modified sequence.
- Returns: An asynchronous sequence of the initial, consecutive elements that satisfy
predicate.
0 declared, 0 inherited