Struct odds::Fix [] [src]

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

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

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

Fix only supports function call notation with the nightly channel and the cargo feature ‘unstable’ enabled.

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];
let all_true = |f: Fix<_, _>, x| {
    let x: &[_] = x;
    x.len() == 0 || x[0] && f.call(&x[1..])
};
let all = Fix(&all_true);
assert_eq!(all.call(data), false);

Methods

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

fn call(&self, arg: T) -> R

Trait Implementations

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

fn clone(&self) -> Self

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more

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