Init Scripts in new repo
This commit is contained in:
31
Functional/None.cs
Normal file
31
Functional/None.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace SJK.Functional;
|
||||
|
||||
public sealed class None<T> : IOption<T>
|
||||
{
|
||||
|
||||
public static None<T> Of() => new();
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public TResult Match<TResult>(Func<T, TResult> _, Func<TResult> onNone) =>
|
||||
onNone();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Match(Action<T> onSome, Action onNone) => onNone();
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public IOption<TResult> Bind<TResult>(Func<T, IOption<TResult>> f) => new None<TResult>();
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public IOption<TResult> Map<TResult>(Func<T, TResult> f) => new None<TResult>();
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public T Or(T aDefault) => aDefault;
|
||||
public T Or(Func<T> aDefault)=>aDefault();
|
||||
public bool HasValue([NotNullWhen(true)]out T? value) => (value = default) is not null && false;
|
||||
public bool HasValue() => false;
|
||||
public override string ToString()
|
||||
{
|
||||
return nameof(None<T>);
|
||||
}
|
||||
|
||||
public bool Equals(IOption<T>? other)=> other is None<T>;
|
||||
}
|
||||
Reference in New Issue
Block a user