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.first(where:)

Returns the first element of the sequence that satisfies the given predicate.

Source and package
Qualified name
ControlNotificationStream.first(where:)
Declared in
ControlNotificationStream
Package
libtmux-swift
first(where: (Self.Element) async throws -> Bool) -> Self .Element?

Inherited from AsyncSequence.first(where:)

Description#

In this example, an asynchronous sequence called Counter produces Int values from 1 to 10. The first(where:) method returns the first member of the sequence that's evenly divisible by both 2 and 3.

let divisibleBy2And3 = await Counter(howHigh: 10) .first { $0 % 2 == 0 && $0 % 3 == 0 } print(divisibleBy2And3 ?? "none") // Prints "6"

The predicate executes each time the asynchronous sequence produces an element, until either the predicate finds a match or the sequence ends.

  • Parameter predicate: A closure that takes an element of the asynchronous sequence as its argument and returns a Boolean value that indicates whether the element is a match.
  • Returns: The first element of the sequence that satisfies predicate, or nil if there is no element that satisfies predicate.
Parameters
Raises
  • any Error – Conditionally propagates errors (rethrows).

Esc

Type to search.

Reference previewOpen reference