flip

Function flip 

Source
pub fn flip<'a, ClonableFnBrand: 'a + ClonableFn, A: 'a, B: 'a + Clone, C: 'a>(
    f: ApplyFn<'a, ClonableFnBrand, A, ApplyFn<'a, ClonableFnBrand, B, C>>,
) -> ApplyFn<'a, ClonableFnBrand, B, ApplyFn<'a, ClonableFnBrand, A, C>>
Expand description

Returns a version of the input curried binary function with its arguments flipped.

§Type Signature

forall a b c. (a -> b -> c) -> b -> a -> c

§Parameters

  • f: A curried binary function.

§Returns

A version of f that takes its arguments in reverse.

§Examples

use fp_library::{brands::RcFnBrand, functions::flip, classes::clonable_fn::ApplyFn};
use std::rc::Rc;

let subtract: ApplyFn<RcFnBrand, _, ApplyFn<RcFnBrand, _, _>> = Rc::new(|a| Rc::new(move |b| a - b));

// 0 - 1 = -1
assert_eq!(
    flip::<RcFnBrand, _, _, _>(subtract)(1)(0),
    -1
);