Table of Contents

Class MapExtensions

Namespace
Trellis
Assembly
Trellis.Core.dll

Provides extension methods for mapping (transforming) values inside Result objects.

public static class MapExtensions
Inheritance
MapExtensions
Inherited Members

Remarks

Map is used when you have a function that always succeeds and you want to transform the value inside a Result without changing its success/failure state. Unlike Bind, Map functions don't return a Result - they return a plain value that gets automatically wrapped in a success Result. If the input Result is a failure, the Map function is skipped and the failure is propagated.

Methods

Map<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)>, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>)

Maps the values of a 9-element tuple result to a new value using the provided function. If the result is a failure, returns the failure without calling the function.

public static Result<TResult> Map<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(this Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)> result, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> func)

Parameters

result Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)>

The result containing a 9-element tuple.

func Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>

The function to transform the tuple elements if the result is successful.

Returns

Result<TResult>

A new success Result containing the transformed value, or the original failure.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

T6

The type of element 6 in the tuple.

T7

The type of element 7 in the tuple.

T8

The type of element 8 in the tuple.

T9

The type of element 9 in the tuple.

TResult

The type of the result value returned by the function.

Examples

var result = FirstName.TryCreate("John")
    .Combine(LastName.TryCreate("Doe"))
    .Combine(Field3.TryCreate("value3"))
    .Combine(Field4.TryCreate("value4"))
    .Combine(Field5.TryCreate("value5"))
    .Combine(Field6.TryCreate("value6"))
    .Combine(Field7.TryCreate("value7"))
    .Combine(Field8.TryCreate("value8"))
    .Combine(Field9.TryCreate("value9"))
    .Map((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) => new Entity(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9));

Map<TIn, TOut>(Result<TIn>, Func<TIn, TOut>)

Maps the value of a successful result to a new value using the provided function. If the result is a failure, returns the failure without calling the function.

public static Result<TOut> Map<TIn, TOut>(this Result<TIn> result, Func<TIn, TOut> func)

Parameters

result Result<TIn>

The result to map.

func Func<TIn, TOut>

The function to transform the value if the result is successful.

Returns

Result<TOut>

A new success result with the transformed value if success; otherwise the original failure.

Type Parameters

TIn

Type of the input result value.

TOut

Type of the output result value.

Remarks

Selector contract. func must not return null. Map wraps the returned value in Ok<TValue>(TValue) unconditionally; a null transformation result yields a "successful" Result<TValue> whose Value is null, which subsequent stages will misinterpret. If the transformation can fail or produce no value, project to Maybe<T> first or use Bind with an explicit Result<TValue>-returning selector.

Map<T1, T2, TResult>(Result<(T1, T2)>, Func<T1, T2, TResult>)

Maps the values of a 2-element tuple result to a new value using the provided function. If the result is a failure, returns the failure without calling the function.

public static Result<TResult> Map<T1, T2, TResult>(this Result<(T1, T2)> result, Func<T1, T2, TResult> func)

Parameters

result Result<(T1, T2)>

The result containing a 2-element tuple.

func Func<T1, T2, TResult>

The function to transform the tuple elements if the result is successful.

Returns

Result<TResult>

A new success Result containing the transformed value, or the original failure.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

TResult

The type of the result value returned by the function.

Examples

var result = FirstName.TryCreate("John")
    .Combine(LastName.TryCreate("Doe"))
    .Map((arg1, arg2) => new Entity(arg1, arg2));

Map<T1, T2, T3, TResult>(Result<(T1, T2, T3)>, Func<T1, T2, T3, TResult>)

Maps the values of a 3-element tuple result to a new value using the provided function. If the result is a failure, returns the failure without calling the function.

public static Result<TResult> Map<T1, T2, T3, TResult>(this Result<(T1, T2, T3)> result, Func<T1, T2, T3, TResult> func)

Parameters

result Result<(T1, T2, T3)>

The result containing a 3-element tuple.

func Func<T1, T2, T3, TResult>

The function to transform the tuple elements if the result is successful.

Returns

Result<TResult>

A new success Result containing the transformed value, or the original failure.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

TResult

The type of the result value returned by the function.

Examples

var result = FirstName.TryCreate("John")
    .Combine(LastName.TryCreate("Doe"))
    .Combine(Field3.TryCreate("value3"))
    .Map((arg1, arg2, arg3) => new Entity(arg1, arg2, arg3));

Map<T1, T2, T3, T4, TResult>(Result<(T1, T2, T3, T4)>, Func<T1, T2, T3, T4, TResult>)

Maps the values of a 4-element tuple result to a new value using the provided function. If the result is a failure, returns the failure without calling the function.

public static Result<TResult> Map<T1, T2, T3, T4, TResult>(this Result<(T1, T2, T3, T4)> result, Func<T1, T2, T3, T4, TResult> func)

Parameters

result Result<(T1, T2, T3, T4)>

The result containing a 4-element tuple.

func Func<T1, T2, T3, T4, TResult>

The function to transform the tuple elements if the result is successful.

Returns

Result<TResult>

A new success Result containing the transformed value, or the original failure.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

TResult

The type of the result value returned by the function.

Examples

var result = FirstName.TryCreate("John")
    .Combine(LastName.TryCreate("Doe"))
    .Combine(Field3.TryCreate("value3"))
    .Combine(Field4.TryCreate("value4"))
    .Map((arg1, arg2, arg3, arg4) => new Entity(arg1, arg2, arg3, arg4));

Map<T1, T2, T3, T4, T5, TResult>(Result<(T1, T2, T3, T4, T5)>, Func<T1, T2, T3, T4, T5, TResult>)

Maps the values of a 5-element tuple result to a new value using the provided function. If the result is a failure, returns the failure without calling the function.

public static Result<TResult> Map<T1, T2, T3, T4, T5, TResult>(this Result<(T1, T2, T3, T4, T5)> result, Func<T1, T2, T3, T4, T5, TResult> func)

Parameters

result Result<(T1, T2, T3, T4, T5)>

The result containing a 5-element tuple.

func Func<T1, T2, T3, T4, T5, TResult>

The function to transform the tuple elements if the result is successful.

Returns

Result<TResult>

A new success Result containing the transformed value, or the original failure.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

TResult

The type of the result value returned by the function.

Examples

var result = FirstName.TryCreate("John")
    .Combine(LastName.TryCreate("Doe"))
    .Combine(Field3.TryCreate("value3"))
    .Combine(Field4.TryCreate("value4"))
    .Combine(Field5.TryCreate("value5"))
    .Map((arg1, arg2, arg3, arg4, arg5) => new Entity(arg1, arg2, arg3, arg4, arg5));

Map<T1, T2, T3, T4, T5, T6, TResult>(Result<(T1, T2, T3, T4, T5, T6)>, Func<T1, T2, T3, T4, T5, T6, TResult>)

Maps the values of a 6-element tuple result to a new value using the provided function. If the result is a failure, returns the failure without calling the function.

public static Result<TResult> Map<T1, T2, T3, T4, T5, T6, TResult>(this Result<(T1, T2, T3, T4, T5, T6)> result, Func<T1, T2, T3, T4, T5, T6, TResult> func)

Parameters

result Result<(T1, T2, T3, T4, T5, T6)>

The result containing a 6-element tuple.

func Func<T1, T2, T3, T4, T5, T6, TResult>

The function to transform the tuple elements if the result is successful.

Returns

Result<TResult>

A new success Result containing the transformed value, or the original failure.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

T6

The type of element 6 in the tuple.

TResult

The type of the result value returned by the function.

Examples

var result = FirstName.TryCreate("John")
    .Combine(LastName.TryCreate("Doe"))
    .Combine(Field3.TryCreate("value3"))
    .Combine(Field4.TryCreate("value4"))
    .Combine(Field5.TryCreate("value5"))
    .Combine(Field6.TryCreate("value6"))
    .Map((arg1, arg2, arg3, arg4, arg5, arg6) => new Entity(arg1, arg2, arg3, arg4, arg5, arg6));

Map<T1, T2, T3, T4, T5, T6, T7, TResult>(Result<(T1, T2, T3, T4, T5, T6, T7)>, Func<T1, T2, T3, T4, T5, T6, T7, TResult>)

Maps the values of a 7-element tuple result to a new value using the provided function. If the result is a failure, returns the failure without calling the function.

public static Result<TResult> Map<T1, T2, T3, T4, T5, T6, T7, TResult>(this Result<(T1, T2, T3, T4, T5, T6, T7)> result, Func<T1, T2, T3, T4, T5, T6, T7, TResult> func)

Parameters

result Result<(T1, T2, T3, T4, T5, T6, T7)>

The result containing a 7-element tuple.

func Func<T1, T2, T3, T4, T5, T6, T7, TResult>

The function to transform the tuple elements if the result is successful.

Returns

Result<TResult>

A new success Result containing the transformed value, or the original failure.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

T6

The type of element 6 in the tuple.

T7

The type of element 7 in the tuple.

TResult

The type of the result value returned by the function.

Examples

var result = FirstName.TryCreate("John")
    .Combine(LastName.TryCreate("Doe"))
    .Combine(Field3.TryCreate("value3"))
    .Combine(Field4.TryCreate("value4"))
    .Combine(Field5.TryCreate("value5"))
    .Combine(Field6.TryCreate("value6"))
    .Combine(Field7.TryCreate("value7"))
    .Map((arg1, arg2, arg3, arg4, arg5, arg6, arg7) => new Entity(arg1, arg2, arg3, arg4, arg5, arg6, arg7));

Map<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(Result<(T1, T2, T3, T4, T5, T6, T7, T8)>, Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult>)

Maps the values of a 8-element tuple result to a new value using the provided function. If the result is a failure, returns the failure without calling the function.

public static Result<TResult> Map<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(this Result<(T1, T2, T3, T4, T5, T6, T7, T8)> result, Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> func)

Parameters

result Result<(T1, T2, T3, T4, T5, T6, T7, T8)>

The result containing a 8-element tuple.

func Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult>

The function to transform the tuple elements if the result is successful.

Returns

Result<TResult>

A new success Result containing the transformed value, or the original failure.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

T6

The type of element 6 in the tuple.

T7

The type of element 7 in the tuple.

T8

The type of element 8 in the tuple.

TResult

The type of the result value returned by the function.

Examples

var result = FirstName.TryCreate("John")
    .Combine(LastName.TryCreate("Doe"))
    .Combine(Field3.TryCreate("value3"))
    .Combine(Field4.TryCreate("value4"))
    .Combine(Field5.TryCreate("value5"))
    .Combine(Field6.TryCreate("value6"))
    .Combine(Field7.TryCreate("value7"))
    .Combine(Field8.TryCreate("value8"))
    .Map((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) => new Entity(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8));