Documentation Language: Swift

Function

reject(_:_:)

Rejects all elements from a collection that satisfy the given predicate.

func reject(_ 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 do not satisfy the predicate

Discussion

The reject operation is the inverse of select, filtering a collection to exclude elements for which the predicate returns true. This operation preserves the original order of remaining elements.

Examples

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