Skip to main content

FilterMapFn

Trait FilterMapFn 

Source
pub trait FilterMapFn<I, T, U>: Send + 'static {
    // Required method
    fn execute(&self, id: &I, data: T) -> Result<Option<U>>;
}
Expand description

Filter map function.

This trait defines a function that transforms data of type T into optional data of type U. It’s fundamentally the combination of the MapFn and FilterFn traits, as it allows for filtering and mapping data as part of a single operation. Since transformations can be expensive, this trait expects owned data, so that operators are able to move the function into a Task for execution on a worker thread.

There’s a range of different implementations of this trait, allowing you to use a variety of function shapes, including support for Splat, as well as support for the [WithId] and [WithSplat] adapters. Furthermore, the trait can be implemented for custom types to add new behaviors. Note that all implementations also allow to return a Report, which makes it possible to return diagnostics from the function execution.

The 'static lifetimes is mandatory as closures must be moved into actions, so requiring it here allows us to reduce the verbosity of trait bounds.

§Examples

Transform and filter data:

use zrx_stream::function::FilterMapFn;

// Define and execute function
let f = |n: i32| (n > 0).then(|| n * n);
f.execute(&"id", 42)?;

Transform and filter data with splat argument:

use zrx_stream::function::{FilterMapFn, Splat};

// Define and execute function
let f = |a: i32, b: i32| (a < b).then(|| a + b);
f.execute(&"id", Splat::from((1, 2)))?;

Required Methods§

Source

fn execute(&self, id: &I, data: T) -> Result<Option<U>>

Executes the filter map function.

§Errors

This method returns an error if the function fails to execute.

Implementors§

Source§

impl<F, R, I, T1, T2, T3, T4, T5, T6, T7, T8, U> FilterMapFn<I, Splat<(T1, T2, T3, T4, T5, T6, T7, T8)>, U> for F
where F: Fn(T1, T2, T3, T4, T5, T6, T7, T8) -> R + Send + 'static, R: IntoReport<Option<U>>, I: Display,

Source§

impl<F, R, I, T1, T2, T3, T4, T5, T6, T7, U> FilterMapFn<I, Splat<(T1, T2, T3, T4, T5, T6, T7)>, U> for F
where F: Fn(T1, T2, T3, T4, T5, T6, T7) -> R + Send + 'static, R: IntoReport<Option<U>>, I: Display,

Source§

impl<F, R, I, T1, T2, T3, T4, T5, T6, U> FilterMapFn<I, Splat<(T1, T2, T3, T4, T5, T6)>, U> for F
where F: Fn(T1, T2, T3, T4, T5, T6) -> R + Send + 'static, R: IntoReport<Option<U>>, I: Display,

Source§

impl<F, R, I, T1, T2, T3, T4, T5, U> FilterMapFn<I, Splat<(T1, T2, T3, T4, T5)>, U> for F
where F: Fn(T1, T2, T3, T4, T5) -> R + Send + 'static, R: IntoReport<Option<U>>, I: Display,

Source§

impl<F, R, I, T1, T2, T3, T4, U> FilterMapFn<I, Splat<(T1, T2, T3, T4)>, U> for F
where F: Fn(T1, T2, T3, T4) -> R + Send + 'static, R: IntoReport<Option<U>>, I: Display,

Source§

impl<F, R, I, T1, T2, T3, U> FilterMapFn<I, Splat<(T1, T2, T3)>, U> for F
where F: Fn(T1, T2, T3) -> R + Send + 'static, R: IntoReport<Option<U>>, I: Display,

Source§

impl<F, R, I, T1, T2, U> FilterMapFn<I, Splat<(T1, T2)>, U> for F
where F: Fn(T1, T2) -> R + Send + 'static, R: IntoReport<Option<U>>, I: Display,

Source§

impl<F, R, I, T1, U> FilterMapFn<I, Splat<(T1,)>, U> for F
where F: Fn(T1) -> R + Send + 'static, R: IntoReport<Option<U>>, I: Display,

Source§

impl<F, R, I, T, U> FilterMapFn<I, T, U> for F
where F: Fn(T) -> R + Send + 'static, R: IntoReport<Option<U>>, I: Display, T: Value,