Documentation Language: Swift

Function

forAll(_:_:)

Tests whether all elements in the collection satisfy the given predicate.

func forAll(_ 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 all elements satisfy the predicate, false otherwise

Discussion

The forAll operation returns true if every element in the collection satisfies the predicate. If the collection is empty, it returns true (vacuous truth).

Examples

let numbers = [2, 4, 6, 8] as [EInt]
let allEven = try forAll(numbers) { ($0 as? EInt ?? 0) % 2 == 0 }
// Result: true