pub fn filter_scales<F>(filter: F) -> Result<Vec<Scale>, ScaleOmnibusError>Expand description
Filters scales based on a provided closure.
§Arguments
filter- A closure that takes a&Scaleand returnstrueif the scale matches the filter.
§Returns
A Vec<Scale> containing the filtered scales.
§Example
// Find all the scales with "Major" in the name:
let major_scales = scale_omnibus::filter_scales(|scale| scale.name.contains("Major")).unwrap();
// Bebop Major is among them:
assert!(major_scales.contains(&scale_omnibus::get_scale("Bebop Major").unwrap()));
// Find all the scales with 12 intervals:
let filtered_scales = scale_omnibus::filter_scales(|scale| {
scale
.intervals
.as_ref()
.map_or(false, |intervals| intervals.len() == 12)
}).unwrap();
// Well, there's only one of those:
assert_eq!(filtered_scales, vec![scale_omnibus::get_scale("Chromatic").unwrap().clone()]);