higher_order_functions

Trait Map

Source
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§

Source

type TFrom

The type of values being mapped over.

Source

type TOut<TTo>

The generic type of the result after mapping.

Required Methods§

Source

fn map<TTo, F: FnMut(Self::TFrom) -> TTo>(self, f: F) -> Self::TOut<TTo>

Apply a function to the inner values of this type.

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.

Source§

type TFrom = TFrom

Source§

type TOut<TTo> = LinkedList<TTo>

Source§

fn map<TTo, F: FnMut(TFrom) -> TTo>(self, f: F) -> Self::TOut<TTo>

Source§

impl<TFrom> Map for VecDeque<TFrom>

Apply a function to all values of the VecDeque.

Source§

type TFrom = TFrom

Source§

type TOut<TTo> = VecDeque<TTo>

Source§

fn map<TTo, F: FnMut(TFrom) -> TTo>(self, f: F) -> Self::TOut<TTo>

Source§

impl<TFrom> Map for Vec<TFrom>

Apply a function to all elements of the Vec.

Source§

type TFrom = TFrom

Source§

type TOut<TTo> = Vec<TTo>

Source§

fn map<TTo, F: FnMut(TFrom) -> TTo>(self, f: F) -> Self::TOut<TTo>

Source§

impl<TFrom, const N: usize> Map for [TFrom; N]

Apply a function to all elements of the array.

Source§

type TFrom = TFrom

Source§

type TOut<TTo> = [TTo; N]

Source§

fn map<TTo, F: FnMut(TFrom) -> TTo>(self, f: F) -> Self::TOut<TTo>

Source§

impl<TKey, TFrom> Map for BTreeMap<TKey, TFrom>
where TKey: Ord,

Apply a function to all values of the BTreeMap.

Source§

type TFrom = TFrom

Source§

type TOut<TTo> = BTreeMap<TKey, TTo>

Source§

fn map<TTo, F: FnMut(TFrom) -> TTo>(self, f: F) -> Self::TOut<TTo>

Source§

impl<TKey, TFrom> Map for HashMap<TKey, TFrom>
where TKey: Hash + Eq,

Apply a function to all values of the HashMap.

Source§

type TFrom = TFrom

Source§

type TOut<TTo> = HashMap<TKey, TTo>

Source§

fn map<TTo, F: FnMut(TFrom) -> TTo>(self, f: F) -> Self::TOut<TTo>

Implementors§