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.
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);
Namespace: Orx.Fun.ResultAssembly: Orx.Fun.Result (in Orx.Fun.Result.dll) Version: 1.3.0+344c8bdd6f720ccfb2d8db7c61b76cf02be18f5f
public static Res<T> OkIfNotnull<T>(
this T value
)
where T : class
- value T
- A nullable value of T to be converted to the result type.
- T
[Missing <typeparam name="T"/> documentation for "M:Orx.Fun.Result.ResultExtensions.OkIfNotnull``1(``0)"]
ResTIn 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).