use crate::{iter::IteratorExt, Array, ArrayExt};
pub trait ArrayMap<U>: Array {
type Map: Array<Item = U>;
#[inline]
fn map<F>(self, f: F) -> Self::Map
where
F: FnMut(Self::Item) -> U,
{
self.iter_move().map(f).collect_array()
}
}
impl<T, U> ArrayMap<U> for [T; 0] {
type Map = [U; 0];
#[inline]
fn map<F>(self, _f: F) -> Self::Map
where
F: FnMut(Self::Item) -> U,
{
[]
}
}
macro_rules! array_map_impl {
($SIZE:expr) => {
impl<T, U> ArrayMap<U> for [T; $SIZE] {
type Map = [U; $SIZE];
}
};
}
array_impls!(array_map_impl);