Table of Contents

Class MapIfExtensions

Namespace
Trellis
Assembly
Trellis.Results.dll

Conditionally transforms the value inside a Result when a condition or predicate is met.

public static class MapIfExtensions
Inheritance
MapIfExtensions
Inherited Members

Methods

MapIf<T>(Result<T>, bool, Func<T, T>)

Transforms the value if the result is successful and the condition is true. Returns the original result unchanged if the condition is false or the result is a failure.

public static Result<T> MapIf<T>(this Result<T> result, bool condition, Func<T, T> func)

Parameters

result Result<T>

The result whose value may be transformed.

condition bool

The boolean condition that must be true for the transformation to apply.

func Func<T, T>

The transformation function to apply to the value.

Returns

Result<T>

A result with the transformed value if successful and condition is true; otherwise the original result.

Type Parameters

T

Type of the result value.

Exceptions

ArgumentNullException

Thrown when func is null.

MapIf<T>(Result<T>, Func<T, bool>, Func<T, T>)

Transforms the value if the result is successful and the predicate returns true for the value. Returns the original result unchanged if the predicate is false or the result is a failure.

public static Result<T> MapIf<T>(this Result<T> result, Func<T, bool> predicate, Func<T, T> func)

Parameters

result Result<T>

The result whose value may be transformed.

predicate Func<T, bool>

The predicate function to test the value against.

func Func<T, T>

The transformation function to apply to the value.

Returns

Result<T>

A result with the transformed value if successful and predicate is true; otherwise the original result.

Type Parameters

T

Type of the result value.

Exceptions

ArgumentNullException

Thrown when predicate or func is null.