fix_fn

Crates.iofix_fn
lib.rsfix_fn
version1.0.2
sourcesrc
created_at2020-05-31 13:09:41.936191
updated_at2020-05-31 20:12:09.000125
descriptionMacro to create recursive closures (similar to the Y combinator).
homepagehttps://crates.io/crates/fix_fn
repositoryhttps://github.com/SrTobi/fix_fn
max_upload_size
id248154
size7,548
Tobias Kahlert (SrTobi)

documentation

README

Build Creates.io Docs

fix_fn

This library enables the creation of recursive closures by providing a single macro fix_fn. The functionality is similar to the Y combinator. Recursive closures can have arbitrary amounts of parameters and can capture variables.

use fix_fn::fix_fn;
let fib = fix_fn!(|fib, i: u32| -> u32 {
    if i <= 1 {
           i
    } else {
        // fib will call the closure recursively
        fib(i - 1) + fib(i - 2)
    }
});

assert_eq!(fib(7), 13);
Commit count: 12

cargo fmt