fix_fn 1.0.2

Macro to create recursive closures (similar to the Y combinator).
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented2 out of 2 items with examples
  • Size
  • Source code size: 7.17 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.08 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • SrTobi/fix_fn
    7 2 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • SrTobi

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);