topic: closures
closures in rust capture their environment by value or by reference.
different from python lambdas -- rust closures have explicit capture rules.
concepts to demonstrate
- closure syntax:
|args| body
- capturing by reference vs by value (
move keyword)
Fn, FnMut, FnOnce trait bounds
- closures as function arguments (higher-order functions)
- returning closures from functions
patriots theme
aggregate patriots season stats using closures passed to fold and map.
build a stat_filter closure factory for different position groups.
file
src/closures/stat_aggregator.rs
reference
python mirror: libraries_2_statistics_2023_patriots_qb_shuffle.py