Table of Contents

Class MatchExtensions

Namespace
FunctionalDdd
Assembly
FunctionalDdd.RailwayOrientedProgramming.dll

Pattern matching helpers (Match / Switch) for Result.

public static class MatchExtensions
Inheritance
MatchExtensions
Inherited Members

Methods

Match<TIn, TOut>(Result<TIn>, Func<TIn, TOut>, Func<Error, TOut>)

Executes either the success or failure function based on the result state.

public static TOut Match<TIn, TOut>(this Result<TIn> result, Func<TIn, TOut> onSuccess, Func<Error, TOut> onFailure)

Parameters

result Result<TIn>

The result to match on.

onSuccess Func<TIn, TOut>

Function to execute on success.

onFailure Func<Error, TOut>

Function to execute on failure.

Returns

TOut

The output from either the success or failure function.

Type Parameters

TIn

Type of the result value.

TOut

Type of the output.

Switch<TIn>(Result<TIn>, Action<TIn>, Action<Error>)

Executes either the success or failure action based on the result state.

public static void Switch<TIn>(this Result<TIn> result, Action<TIn> onSuccess, Action<Error> onFailure)

Parameters

result Result<TIn>

The result to switch on.

onSuccess Action<TIn>

Action to execute on success.

onFailure Action<Error>

Action to execute on failure.

Type Parameters

TIn

Type of the result value.