Core Library0.xAPI Reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

method libtmux-swift latest

ControlNotificationStream.prefix(while:)

Returns an asynchronous sequence, containing the initial, consecutive elements of the base sequence that satisfy the given predicate.

Source and package
Qualified name
ControlNotificationStream.prefix(while:)
Declared in
ControlNotificationStream
Package
libtmux-swift
prefix(while: (Self.Element) async -> Bool) -> AsyncPrefixWhileSequence<Self>

Inherited from AsyncSequence.prefix(while:)

Description#

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 returns false.

In this example, an asynchronous sequence called Counter produces Int values from 1 to 10. The prefix(while:) method causes the modified sequence to pass along values so long as they aren’t divisible by 2 and 3. Upon reaching 6, 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.
Parameters
Raises
  • any Error – Conditionally propagates errors (rethrows).

Esc

Type to search.

Reference previewOpen reference