libtmux Reference MCP Search
On this page

ControlNotificationStream.prefix(while:)

View as Markdown

Declared in
ControlNotificationStream
Package
libtmux-swift
prefix(while:) ( while : (Self.Element) async -> Bool ) AsyncPrefixWhileSequence<Self>
methodasync [source]
methodasync [source]
prefix(while:)

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

0 declared, 0 inherited

Esc

Type to search.