pub trait Map {
type TFrom;
type TOut<TTo>;
// Required method
fn map<TTo, F: FnMut(Self::TFrom) -> TTo>(self, f: F) -> Self::TOut<TTo>;
}
Expand description
Types containing ‘inner’ values which can be mapped over.
§Examples
Multiplying an array by 2:
use higher_order_functions::Map;
let arr = [1, 4, 6, -3, 6].map(|x| x * 2);
assert_eq!(arr, [2, 8, 12, -6, 12]);
Converting an i32 array to an f64 array:
use higher_order_functions::Map;
let arr = [1, 4, 6, -3, 6].map(f64::from);
assert_eq!(arr, [1.0, 4.0, 6.0, -3.0, 6.0]);
Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<TFrom> Map for LinkedList<TFrom>
Apply a function to all values of the LinkedList.
impl<TFrom> Map for LinkedList<TFrom>
Apply a function to all values of the LinkedList.
Source§impl<TFrom, const N: usize> Map for [TFrom; N]
Apply a function to all elements of the array.
impl<TFrom, const N: usize> Map for [TFrom; N]
Apply a function to all elements of the array.
Source§impl<TKey, TFrom> Map for BTreeMap<TKey, TFrom>where
TKey: Ord,
Apply a function to all values of the BTreeMap.
impl<TKey, TFrom> Map for BTreeMap<TKey, TFrom>where
TKey: Ord,
Apply a function to all values of the BTreeMap.