Skip to main content

Module step

Module step 

Source
Expand description

Control type representing Loop/Done states for tail-recursive computations.

Used by MonadRec to implement stack-safe tail recursion. Step::Loop continues iteration, while Step::Done terminates with a result.

§Examples

use fp_library::types::*;

// Count down from n to 0, accumulating the sum
fn sum_to_zero(n: i32, acc: i32) -> Step<(i32, i32), i32> {
    if n <= 0 {
        Step::Done(acc)
    } else {
        Step::Loop((n - 1, acc + n))
    }
}

Enums§

Step
Represents the result of a single step in a tail-recursive computation.