Added HasValue and ifSome/None, and Member not null; for Option.Value
All checks were successful
Build NuGet / build (push) Successful in 40s
All checks were successful
Build NuGet / build (push) Successful in 40s
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Numerics;
|
||||
using Microsoft.VisualBasic;
|
||||
|
||||
namespace SJK.Functional;
|
||||
|
||||
@@ -97,6 +99,27 @@ public static partial class OptionExtensions
|
||||
}
|
||||
return Option<T>.None;
|
||||
}
|
||||
public static bool HasValue<T>(this Option<T> option,[NotNullWhen(true)] out T result)
|
||||
{
|
||||
result = option.Value!;
|
||||
return option.HasValue;
|
||||
}
|
||||
public static bool IfSome<T>(this Option<T> option, Action<T> action)
|
||||
{
|
||||
if (option.HasValue)
|
||||
{
|
||||
action(option.Value);
|
||||
}
|
||||
return option.HasValue;
|
||||
}
|
||||
public static bool IfNone<T>(this Option<T> option, Action action)
|
||||
{
|
||||
if (!option.HasValue)
|
||||
{
|
||||
action();
|
||||
}
|
||||
return !option.HasValue;
|
||||
}
|
||||
public static Option<T> ToOption<T>(this T? value) => value is null ? Option<T>.None : Option<T>.Some(value);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user