Skip to main content

fold_shape

Function fold_shape 

Source
pub fn fold_shape<N, T>(
    s: &Shape<N>,
    on_base: &dyn Fn() -> T,
    on_optional: &dyn Fn(T, &N, &Shape<N>) -> T,
    on_iterable: &dyn Fn(T) -> T,
) -> T
Expand description

Bottom-up fold over the layer stack: compute the leaf value with on_base, then apply on_optional / on_iterable for each wrapping layer from the inside out. on_optional also receives the layer’s payload &N and the Shape it wraps, so callers can special-case e.g. a layer sitting directly over the leaf.

This is the generalization of jnigen’s former fold_strategy.