Skip to content

@filter

Keep elements of an array for which a helper returns truthy.

Returns: array

@filter(arr fn)
Name Type Description
arr array Source array
fn helper Predicate helper returning bool
# Filter positive numbers
def @isPositive "$n: number -> bool" @bool($n > 0)
set $nums [-1 2 -3 4]
set $pos @filter($nums @isPositive)
  • @find — return the first match
  • @all — check if all elements match
  • @any — check if any element matches
  • @map — transform each element