Documentation Language: Swift

Function

exists(_:_:)

Tests whether at least one element in the collection satisfies the given predicate.

func exists(_ collection: any EcoreValue, _ predicate: (any EcoreValue) throws -> Bool) throws -> Bool

Parameters

collection

The collection to test

predicate

A closure that takes an element and returns a Boolean value

Return Value

true if any element satisfies the predicate, false otherwise

Discussion

The exists operation returns true if any element in the collection satisfies the predicate. If the collection is empty, it returns false.

Examples

let numbers = [1, 2, 3, 4, 5] as [EInt]
let hasEven = try exists(numbers) { ($0 as? EInt ?? 0) % 2 == 0 }
// Result: true