ResultExtensionsOkIfT(Boolean, FuncT, String) Method

Creates a result of T as Ok variant with value lazyGetValue() if the okCondition holds. Otherwise, it will map into an Err. Note that the lazyGetValue is only evaluated if the okCondition holds.
C#
Res<User> user = TryGetUser();
// create a database connection (expensive) only if the user IsOk.
Res<Conn> conn = OkIf(user.IsOk, () => CreateDatabaseConnection());

Definition

Namespace: Orx.Fun.Result
Assembly: Orx.Fun.Result (in Orx.Fun.Result.dll) Version: 1.3.0+344c8bdd6f720ccfb2d8db7c61b76cf02be18f5f
C#
public static Res<T> OkIf<T>(
	bool okCondition,
	Func<T> lazyGetValue,
	string strOkCondition = ""
)

Parameters

okCondition  Boolean
Condition that must hold for the return value to be Ok(value).
lazyGetValue  FuncT
Function to create the underlying value of the Ok variant to be returned if okCondition holds.
strOkCondition  String  (Optional)
Name of the condition; to be appended to the error message if it does not hold. Omitting the argument will automatically be filled with the condition's expression in the caller side.

Type Parameters

T

[Missing <typeparam name="T"/> documentation for "M:Orx.Fun.Result.ResultExtensions.OkIf``1(System.Boolean,System.Func{``0},System.String)"]

Return Value

ResT

See Also