liveBook · Manning

Filtering

As explained in Julia as a Second Language

Array filtering is an operation that selects or transforms array elements according to a criterion.

Filtering selects elements from a collection when a predicate returns true. A predicate is a function that always returns either true or false. section 4.10

Filtering pizza sales

Define predicates such as islarge or isbbq, then filter sales before mapping each result to its price and reducing the prices with sum. Large pizzas total 37.25, while BBQ chicken pizzas total 37.5. section 4.10.1

ys = filter(p, xs)

Use filter(p, xs) to apply predicate p to collection xs and return the matching subset. section 4.10

Filtering supports increasingly structured selection:

  • Apply built-in predicates to ranges, numbers, or characters, such as filter(iseven, 1:10). section 4.10
  • Write predicates that test several object properties, then filter arrays of domain objects such as screws. section 13.5.3
  • Convert filtered results into reusable sets and combine them with set operations. section 13.5.4
  • View filtering as a data-flow stage that transforms incoming data and clarifies complex pipelines. section 3.9

How Julia as a Second Language covers it

How deep it goes
Explains predicate-based selection, demonstrates built-in and custom predicates, and combines filtering with mapping, reduction, and sets.
Examples
Demonstrates even numbers, characters, pizza sales, and screw objects selected through single- and multi-criterion predicates.
What it assumes
Assumes basic collections and functions while teaching predicates and their use with arrays and domain objects.
What you can do after
Apply it via Julia's filter function to select matching values and feed them into mapping, reductions, or set operations.
How it connects
Connects filtering with predicates, higher-order functions, arrays, mapping, reduction, data flow, and sets.

Also explained in

Compare how 33 books explain filtering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Julia as a Second Language. The section links point to the parts of the book it draws on.