Trait Unary

Source
pub trait Unary<A> {
    type Output;

    // Required method
    fn then<B>(
        self,
        f: impl Fn(Self::Output) -> B + Clone + Send,
    ) -> impl Fn(A) -> B + Clone + Send;
}
Expand description

A function that takes one argument.

Required Associated Types§

Source

type Output

The return type of the function.

Required Methods§

Source

fn then<B>( self, f: impl Fn(Self::Output) -> B + Clone + Send, ) -> impl Fn(A) -> B + Clone + Send

Creates a new function that takes the output of the current function and passes it as input to the given one; effectively creating a pipeline or chain.

use function::Unary;

fn halven(n: u32) -> u32 {
    n / 2
}

fn is_even(n: u32) -> bool {
    n % 2 == 0
}

let is_half_even = halven.then(is_even);

assert!(is_half_even(4));
assert!(!is_half_even(6));

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.

Implementors§

Source§

impl<F, A, O> Unary<A> for F
where F: Fn(A) -> O + Clone + Send,