[][src]Struct odds::Fix

pub struct Fix<'a, T: 'a, R: 'a = T>(pub &'a dyn Fn(Fix<T, R>, T) -> R);

Fixpoint combinator for rust closures, generalized over the return type.

Note: Use this best through the fix function.

In Fix<T, R>, T is the argument type, and R is the return type, R defaults to T.

Calling the Fix value only supports function call notation with the nightly channel and the crate feature ‘unstable’ enabled; use the .call() method otherwise.

use odds::Fix;
use odds::fix;

let c = |f: Fix<i32>, x| if x == 0 { 1 } else { x * f.call(x - 1) };
let fact = Fix(&c);
assert_eq!(fact.call(5), 120);

let data = [true, false];
assert!(!fix(&data[..], |f, x| {
    x.len() == 0 || x[0] && f.call(&x[1..])
}));

Methods

impl<'a, T, R> Fix<'a, T, R>[src]

pub fn call(&self, arg: T) -> R[src]

Call the fix using the argument arg

Trait Implementations

impl<'a, T, R> Clone for Fix<'a, T, R>[src]

impl<'a, T, R> Copy for Fix<'a, T, R>[src]

Auto Trait Implementations

impl<'a, T, R = T> !RefUnwindSafe for Fix<'a, T, R>

impl<'a, T, R = T> !Send for Fix<'a, T, R>

impl<'a, T, R = T> !Sync for Fix<'a, T, R>

impl<'a, T, R> Unpin for Fix<'a, T, R>

impl<'a, T, R = T> !UnwindSafe for Fix<'a, T, R>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.