ResultExtensionsOkIfNotnullT Method

Creates a result of T as Ok variant with the given value. However, if the value is null, it will map into Err.
C#
string name = null;
static string? GetName(int id)
    => id == 0 ? "Mr Crabs" : null;
Res<string> resName = GetName(0).OkIfNotnull();
Assert.Equal(Ok("Mr Crabs"), resName);

resName = GetName(42).OkIfNotnull();
Assert.True(resName.IsErr);

Definition

Namespace: Orx.Fun.Result
Assembly: Orx.Fun.Result (in Orx.Fun.Result.dll) Version: 1.3.0+344c8bdd6f720ccfb2d8db7c61b76cf02be18f5f
C#
public static Res<T> OkIfNotnull<T>(
	this T value
)
where T : class

Parameters

value  T
A nullable value of T to be converted to the result type.

Type Parameters

T

[Missing <typeparam name="T"/> documentation for "M:Orx.Fun.Result.ResultExtensions.OkIfNotnull``1(``0)"]

Return Value

ResT

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type T. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

See Also