Function sycamore_reactive::map_keyed[][src]

pub fn map_keyed<T, K, U>(
    list: StateHandle<Vec<T>>,
    map_fn: impl Fn(&T) -> U + 'static,
    key_fn: impl Fn(&T) -> K + 'static
) -> impl FnMut() -> Vec<U> where
    T: Eq + Clone,
    K: Eq + Hash,
    U: Clone + 'static, 
Expand description

Function that maps a Vec to another Vec via a map function. The mapped Vec is lazy computed, meaning that it’s value will only be updated when requested. Modifications to the input Vec are diffed using keys to prevent recomputing values that have not changed.

This function is the underlying utility behind Keyed.

Params

  • list - The list to be mapped. The list must be a StateHandle (obtained from a Signal) and therefore reactive.
  • map_fn - A closure that maps from the input type to the output type.
  • key_fn - A closure that returns an unique key to each entry.

Credits: Based on TypeScript implementation in https://github.com/solidjs/solid