Unstable 0.17.0.0
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
namespace Barotrauma
|
||||
{
|
||||
public sealed class None<T> : Option<T>
|
||||
{
|
||||
private None() { }
|
||||
|
||||
public static Option<T> Create() => new None<T>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Barotrauma
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <a href="https://en.wikipedia.org/wiki/Option_type">Option type</a>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Credit <a href="https://github.com/Jlobblet/FunctionalStuff/tree/main/src/FunctionalStuff/Option">Jlobblet</a>
|
||||
/// </remarks>
|
||||
public abstract class Option<T>
|
||||
{
|
||||
public static Option<T> Some(T value) => Some<T>.Create(value);
|
||||
public static Option<T> None() => None<T>.Create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public sealed class Some<T> : Option<T>
|
||||
{
|
||||
public readonly T Value;
|
||||
|
||||
private Some(T value)
|
||||
{
|
||||
if (value is null) { throw new ArgumentNullException(nameof(value), "Some<T> cannot contain null"); }
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static Option<T> Create(T value) => new Some<T>(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user