OptionExtensionsSomeIfNotnullT Method

Creates an option of T as Some variant with the given value. However, if the value is null, it will map into None.
C#
string name = null;
static string? GetName(int id)
    => id == 0 ? "Mr Crabs" : null;
Opt<string> optName = GetName(0).SomeIfNotnull();
Assert.Equal(Some("Mr Crabs"), optName);

optName = GetName(42).SomeIfNotnull();
Assert.True(optName.IsNone);

Definition

Namespace: Orx.Fun.Option
Assembly: Orx.Fun.Option (in Orx.Fun.Option.dll) Version: 1.2.1+ea79806fa5e0e04bfdaef2a1916930e75e2cde74
C#
public static Opt<T> SomeIfNotnull<T>(
	this T value
)
where T : class

Parameters

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

Type Parameters

T

[Missing <typeparam name="T"/> documentation for "M:Orx.Fun.Option.OptionExtensions.SomeIfNotnull``1(``0)"]

Return Value

OptT

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