Table of Contents

Method SomeIf

Namespace
SodaFlow.Functional
Assembly
SodaFlow.Functional.dll

SomeIf<T>(bool, T)

Creates a Maybe<T> containing the given value if a condition holds, and one containing nothing if it does not.

[Pure]
public static Maybe<T> SomeIf<T>(bool condition, T value)

Parameters

condition bool

True to hold the value.

value T

The value to contain when condition holds.

Returns

Maybe<T>

A Maybe<T> containing value if condition is true, and one containing no value otherwise.

Type Parameters

T

The type of the value, inferred from value.

Remarks

This is the translation of an if that gives a value in one branch and has nothing to give in the other. This code evaluates value in each condition, because it is an argument. Where that is not necessary, use SomeIf<T>(bool, Func<T>).

SomeIf<T>(bool, Func<T>)

Creates a Maybe<T> containing the result of the given function if a condition holds, and one containing nothing if it does not.

[Pure]
public static Maybe<T> SomeIf<T>(bool condition, Func<T> valueFactory)

Parameters

condition bool

True to make a value and hold it.

valueFactory Func<T>

Run to give the value when condition holds.

Returns

Maybe<T>

A Maybe<T> containing the result of valueFactory if condition is true, and one containing no value otherwise.

Type Parameters

T

The type of the value, inferred from valueFactory.

Remarks

valueFactory runs only when condition holds. Thus, use this version when the value has a high cost, or when the value is only correct in that condition.