LanguageExt.Core

LanguageExt.Core DataTypes Next

Contents

struct Next <A, B> Source #

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

property bool IsLoop Source #

Returns true if we should loop

property bool IsDone Source #

Returns true if we should complete and return

property A Loop Source #

Try to access the loop-value type

Parameters

returns

Either a valid A value or will throw an exception

property B Done Source #

Try to access the done-value type

Parameters

returns

Either a valid B value or will throw an exception

Methods

method C Match <C> (Func<A, C> Loop, Func<B, C> Done) Source #

Pattern match

method Next<A, C> Map <C> (Func<B, C> f) Source #

method Either<A, B> ToEither () Source #

class Next Source #

Module for the Next data-type

Methods

method Next<A, B> Loop <A, B> (A value) Source #

Continue the recursion

Parameters

type A

Loop value type

type B

Done value type

param value

Value to pass back to the recursive function to 'go around'

returns

Next structure

method Next<A, B> Done <A, B> (B value) Source #

Cancel the recursion and return

Parameters

type A

Loop value type

type B

Loop value type

param value

Final value

returns

Next structure