polars-utils 0.53.0

Private utils for the Polars DataFrame library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
pub fn try_map<T, U, const N: usize>(
    array: [T; N],
    f: impl FnMut(T) -> Option<U>,
) -> Option<[U; N]> {
    let mut array = array.map(f);

    if array.iter().any(Option::is_none) {
        return None;
    }

    Some(std::array::from_fn(|n| array[n].take().unwrap()))
}