UniCoreFW

filter()

Filter elements in array based on func predicate.

Implementation

Args: array: The array to filter func: A function that returns True for items to keep Returns: A new array with only matching items

Example

filter([1, 2, 3], lambda x: x % 2 == 0)

Expected output: [2]

Source Code

def filter(array: List[T], func: Callable[[T], bool]) -> List[T]: return [x for x in array if func(x)]