Skip to content

SrTobi/fix_fn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Rust crate with macro to create recursive closures (similar to the Y combinator).

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages