Table of Contents

Class TryHandlerExtensions

Namespace
PatternKit.Common
Assembly
PatternKit.Core.dll

Extensions that add functional, chainable operations over compiled try-handlers.

public static class TryHandlerExtensions
Inheritance
TryHandlerExtensions
Inherited Members

Methods

FirstMatch<TIn, TOut>(TryHandler[], in TIn)

Returns the first successful result as an Option<T> for fluent chaining.

public static Option<TOut> FirstMatch<TIn, TOut>(this TryStrategy<TIn, TOut>.TryHandler[] handlers, in TIn input)

Parameters

handlers TryHandler[]

The compiled handlers to evaluate.

input TIn

The input value.

Returns

Option<TOut>

Some(T?) with the first successful result, or None() when none succeed.

Type Parameters

TIn

The handler input type.

TOut

The handler output type.

Examples

var value = handlers.FirstMatch(in input).OrDefault();

TryGetResult<TIn, TOut>(TryHandler[], in TIn, out TOut?)

Attempts to obtain the first successful result from a compiled handler array.

public static bool TryGetResult<TIn, TOut>(this TryStrategy<TIn, TOut>.TryHandler[] handlers, in TIn input, out TOut? result)

Parameters

handlers TryHandler[]

The compiled handlers to evaluate.

input TIn

The input value.

result TOut

The first successful result, when found.

Returns

bool

true if any handler succeeds; otherwise false.

Type Parameters

TIn

The handler input type.

TOut

The handler output type.