Skip to main content

Module witherable

Module witherable 

Source
Expand description

Dispatch for witherable operations: Witherable and RefWitherable.

Provides the following dispatch traits and unified free functions:

Each routes to the appropriate trait method based on the closure’s argument type.

§Examples

use fp_library::{
	brands::*,
	functions::explicit::*,
	types::*,
};

// wilt
let y = wilt::<RcFnBrand, OptionBrand, OptionBrand, _, _, _, _, _>(
	|a: i32| Some(if a > 2 { Ok(a) } else { Err(a) }),
	Some(5),
);
assert_eq!(y, Some((None, Some(5))));

// wither
let y = wither::<RcFnBrand, OptionBrand, OptionBrand, _, _, _, _>(
	|a: i32| Some(if a > 2 { Some(a * 2) } else { None }),
	Some(5),
);
assert_eq!(y, Some(Some(10)));

Modules§

explicit
Explicit dispatch functions requiring a Brand turbofish.

Traits§

WiltDispatch
Trait that routes a wilt operation to the appropriate type class method.
WitherDispatch
Trait that routes a wither operation to the appropriate type class method.

Functions§

wilt
Partitions a structure based on a function returning a Result in an applicative context, inferring the brand from the container type.
wither
Maps a function over a data structure and filters out None results in an applicative context, inferring the brand from the container type.