Skip to Content

Iterators and closures

Focus: one iterator pipeline that filters, transforms, limits, and collects a score list.

Open in Playground 

iterators.slx
entry top_scores(scores: u64[], min_score: u64, limit: u32) -> u64[] { return scores .iter() .filter(|score: u64| { return score >= min_score }) .map(|score: u64| { return score * 10 }) .take(limit) .collect() }

How it works

  • scores.iter() creates the lazy iterator pipeline.
  • filter keeps only values greater than or equal to min_score.
  • map applies a multiplier to each selected score.
  • take(limit) bounds the amount of work before collect() materializes the array.
  • collect() turns the lazy pipeline back into a u64[] return value.
Last updated on