pub struct Fix<'a, T: 'a, R: 'a = T>(pub &'a dyn Fn(Fix<'_, T, R>, T) -> R);Expand description
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..])
}));
Tuple Fields§
§0: &'a dyn Fn(Fix<'_, T, R>, T) -> RImplementations§
Trait Implementations§
Auto Trait Implementations§
impl<'a, T, R> Freeze for Fix<'a, T, R>
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more