Iterator adaptors (map, filter, collect)
Në shqip: Metodat e iteratorëve
ShpjegimiSQ
Iteratorët kanë metoda zinxhir si map, filter, enumerate, zip, sum dhe collect. Janë „dembelë“: s'bëjnë asgjë derisa t'i kërkosh rezultatin, dhe kompajlohen aq shpejt sa një cikël i shkruar me dorë.
EnglishEN
Iterators have chainable methods like map, filter, enumerate, zip, sum and collect. They're “lazy”: they do nothing until you ask for the result, and compile as fast as a hand-written loop.
Si ta mendosh
Si një linjë prodhimi ku produktet kalojnë nga një stacion te tjetri.
Lexoje në anglisht
Like a production line where products pass from station to station.
Shembull kodirust
let notat = vec![5, 2, 4, 5];
let kalues: Vec<i32> = notat.iter().filter(|&&n| n >= 2).cloned().collect();
let mesatarja = notat.iter().sum::<i32>() as f64 / notat.len() as f64;