restructure fs

This commit is contained in:
nub31
2025-05-03 16:55:06 +02:00
parent bfc3aad516
commit 3b142b2453
75 changed files with 38 additions and 387 deletions

48
lang/Nub.Lang/Optional.cs Normal file
View File

@@ -0,0 +1,48 @@
using System.Diagnostics.CodeAnalysis;
namespace Nub.Lang;
public readonly struct Optional
{
public static Optional<TValue> Empty<TValue>() => new();
/// <summary>
/// Alias for creating an Optional&lt;TValue&gt; which allows for implicit types
/// </summary>
/// <param name="value"></param>
/// <typeparam name="TValue"></typeparam>
/// <returns></returns>
public static Optional<TValue> OfNullable<TValue>(TValue? value)
{
return value ?? Optional<TValue>.Empty();
}
}
public readonly struct Optional<TValue>
{
public static Optional<TValue> Empty() => new();
public static Optional<TValue> OfNullable(TValue? value)
{
return value ?? Empty();
}
public Optional()
{
Value = default;
HasValue = false;
}
public Optional(TValue value)
{
Value = value;
HasValue = true;
}
public TValue? Value { get; }
[MemberNotNullWhen(true, nameof(Value))]
public bool HasValue { get; }
public static implicit operator Optional<TValue>(TValue value) => new(value);
}