Contents
Simple data type that helps indicate whether a recursive function should loop or not.
This was created to pair with the Monad trait Tail function and is extremely lightweight.
It's designed to cause no additional allocations when used in a tail-recursive manner. That does mean there
are some footguns in here if you're not careful. So, make sure that before you access Loop or Done
that you've confirmed the state of the structure by using IsLoop or IsDone.
You can then use C#'s pattern-matching to extract the value from the structure:
var result = next switch
{
{ IsLoop: true, Loop: var value } => ...,
{ IsDone: true, Done: var value } => ...,
_ => throw new Exception("Invalid state")
};
If we ever get real struct discriminated unions, then this can be replaced with that.
Parameters
| type | A | Loop value type |
| type | B | Done value type |
Properties
Try to access the loop-value type
Parameters
| returns | Either a valid | |