Trait parity_map::ParityMap

source ·
pub trait ParityMap: Sized {
    // Required method
    fn parity(&self) -> Parity;

    // Provided methods
    fn parity_map(
        self,
        odd: impl FnOnce(Self) -> Self,
        even: impl FnOnce(Self) -> Self
    ) -> Self { ... }
    fn parity_map_and_then<F>(
        self,
        odd: impl FnOnce(Self) -> Self,
        even: impl FnOnce(Self) -> Self,
        after: impl FnOnce(Self) -> Self
    ) -> Self { ... }
    fn map_even(self, f: impl FnOnce(Self) -> Self) -> Self { ... }
    fn map_odd(self, f: impl FnOnce(Self) -> Self) -> Self { ... }
}
Expand description

Gives access to methods for mapping based on a number’s parity.

Required Methods§

source

fn parity(&self) -> Parity

Returns the parity of &self

Provided Methods§

source

fn parity_map( self, odd: impl FnOnce(Self) -> Self, even: impl FnOnce(Self) -> Self ) -> Self

Returns odd(self) if self is odd, else even(self).

source

fn parity_map_and_then<F>( self, odd: impl FnOnce(Self) -> Self, even: impl FnOnce(Self) -> Self, after: impl FnOnce(Self) -> Self ) -> Self

Calls a function on the result of self.parity_map(..), returning the result.

source

fn map_even(self, f: impl FnOnce(Self) -> Self) -> Self

Returns f(self) if self is even, else self.

source

fn map_odd(self, f: impl FnOnce(Self) -> Self) -> Self

Returns f(self) if self is odd, else self.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T: Integer> ParityMap for T