PluralKit/Myriad/Utils/Optional.cs
2020-12-25 13:58:45 +01:00

26 lines
586 B
C#

namespace Myriad.Utils
{
public interface IOptional
{
object? GetValue();
}
public readonly struct Optional<T>: IOptional
{
public Optional(T value)
{
HasValue = true;
Value = value;
}
public bool HasValue { get; }
public object? GetValue() => Value;
public T Value { get; }
public static implicit operator Optional<T>(T value) => new(value);
public static Optional<T> Some(T value) => new(value);
public static Optional<T> None() => default;
}
}