Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-utils/src/array.rs
8365 views
1
pub fn try_map<T, U, const N: usize>(
2
array: [T; N],
3
f: impl FnMut(T) -> Option<U>,
4
) -> Option<[U; N]> {
5
let mut array = array.map(f);
6
7
if array.iter().any(Option::is_none) {
8
return None;
9
}
10
11
Some(std::array::from_fn(|n| array[n].take().unwrap()))
12
}
13
14