Function
select(_:_:)
Selects all elements from a collection that satisfy the given predicate.
func select(_ collection: any EcoreValue, _ predicate: (any EcoreValue) throws -> Bool) throws -> [any EcoreValue]
Parameters
collection-
The collection to filter
predicate-
A closure that takes an element and returns a Boolean value
Return Value
A new array containing elements that satisfy the predicate
Discussion
The select operation filters a collection, returning a new collection containing only those elements for which the predicate returns true. This operation preserves the original order of elements.
Examples
let numbers = [1, 2, 3, 4, 5] as [EInt]
let evens = try select(numbers) { ($0 as? EInt ?? 0) % 2 == 0 }
// Result: [2, 4]