Skip to content

Commit

Permalink
fix: optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Dec 20, 2023
1 parent b531e91 commit 3eba8b9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions DisCatSharp/Entities/Optional.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ public interface IOptional

private readonly T _val;

/// <summary>
/// Creates a new <see cref="Optional{T}"/> with specified value.
/// </summary>
/// <param name="value">Value of this option.</param>
public Optional(T value)
{
this._val = value;
this.HasValue = true;
}

/// <summary>
/// Performs a mapping operation on the current <see cref="Optional{T}"/>, turning it into an Optional holding a
/// <typeparamref name="TOut"/> instance if the source optional contains a value; otherwise, returns an
Expand Down Expand Up @@ -214,9 +224,7 @@ public override int GetHashCode()
=> this.Map(x => x.GetHashCode()).ValueOrDefault();

public static implicit operator Optional<T>(T val)
#pragma warning disable 0618
=> Optional.Some(val);
#pragma warning restore 0618
=> new(val);

public static explicit operator T(Optional<T> opt)
=> opt.Value;
Expand Down

0 comments on commit 3eba8b9

Please sign in to comment.