Skip to content

Commit

Permalink
see refs in comments for option result and result option
Browse files Browse the repository at this point in the history
  • Loading branch information
pimbrouwers committed Aug 28, 2024
1 parent 8a1f6ae commit 2596a80
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 63 deletions.
44 changes: 22 additions & 22 deletions src/Danom/Option/Option.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ private Option(T t)
}

/// <summary>
/// Returns true if Option is Some, false otherwise.
/// Returns true if <see cref="Option{T}"/> is Some, false otherwise.
/// </summary>
public bool IsSome { get; } = false;

/// <summary>
/// Returns true if Option is None, false otherwise.
/// Returns true if <see cref="Option{T}"/> is None, false otherwise.
/// </summary>
public bool IsNone => !IsSome;

/// <summary>
/// If Option is Some evaluate the some delegate, otherwise none.
/// If <see cref="Option{T}"/> is Some evaluate the some delegate, otherwise none.
/// </summary>
/// <typeparam name="U"></typeparam>
/// <param name="some"></param>
Expand All @@ -42,7 +42,7 @@ public U Match<U>(Func<T, U> some, Func<U> none) =>
none();

/// <summary>
/// Evaluates the bind delegate if Option is Some otherwise return None.
/// Evaluates the bind delegate if <see cref="Option{T}"/> is Some otherwise return None.
/// </summary>
/// <typeparam name="U"></typeparam>
/// <param name="bind"></param>
Expand All @@ -52,7 +52,7 @@ public Option<U> Bind<U>(
Match(bind, Option<U>.None);

/// <summary>
/// Evaluates the map delegate if Option is Some otherwise return None.
/// Evaluates the map delegate if <see cref="Option{T}"/> is Some otherwise return None.
/// </summary>
/// <typeparam name="U"></typeparam>
/// <param name="map"></param>
Expand All @@ -62,7 +62,7 @@ public Option<U> Map<U>(
Bind(x => Option<U>.Some(map(x)));

/// <summary>
/// Returns the value of Option if it is T otherwise return default.
/// Returns the value of <see cref="Option{T}"/> if it is T otherwise return default.
/// </summary>
/// <param name="defaultValue"></param>
/// <returns></returns>
Expand All @@ -71,7 +71,7 @@ public T DefaultValue(
Match(some => some, () => defaultValue);

/// <summary>
/// Returns the value of Option if it is T otherwise evaluate default.
/// Returns the value of <see cref="Option{T}"/> if it is T otherwise evaluate default.
/// </summary>
/// <param name="defaultWith"></param>
/// <returns></returns>
Expand All @@ -80,7 +80,7 @@ public T DefaultWith(
Match(some => some, () => defaultWith());

/// <summary>
/// Return Option if it is Some, otherwise return ifNone.
/// Return <see cref="Option{T}"/> if it is Some, otherwise return ifNone.
/// </summary>
/// <param name="ifNone"></param>
/// <returns></returns>
Expand All @@ -89,7 +89,7 @@ public Option<T> OrElse(
Match(Option<T>.Some, () => ifNone);

/// <summary>
/// Return Option if it is Some, otherwise evaluate ifNoneWith.
/// Return <see cref="Option{T}"/> if it is Some, otherwise evaluate ifNoneWith.
/// </summary>
/// <param name="ifNoneWith"></param>
/// <returns></returns>
Expand All @@ -99,45 +99,45 @@ public Option<T> OrElseWith(


/// <summary>
/// Creates a new Option with the specified value.
/// Creates a new <see cref="Option{T}"/> with the specified value.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static Option<T> Some(T value) =>
new(value);

/// <summary>
/// Creates Option with the specified value wrapped in a completed Task.
/// Creates <see cref="Option{T}"/> with the specified value wrapped in a completed Task.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static Task<Option<T>> SomeAsync(T value) =>
Task.FromResult(Some(value));

/// <summary>
/// Creates a new Option with the value of the awaited Task.
/// Creates a new <see cref="Option{T}"/> with the value of the awaited Task.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static async Task<Option<T>> SomeAsync(Task<T> value) =>
Some(await value);

/// <summary>
/// Creates a new Option with no value.
/// Creates a new <see cref="Option{T}"/> with no value.
/// </summary>
/// <returns></returns>
public static Option<T> None() =>
new();

/// <summary>
/// Creates a new Option with no value wrapped in a completed Task.
/// Creates a new <see cref="Option{T}"/> with no value wrapped in a completed Task.
/// </summary>
/// <returns></returns>
public static Task<Option<T>> NoneAsync() =>
Task.FromResult(None());

/// <summary>
/// Returns true if the specified Options are equal.
/// Returns true if the specified <see cref="Option{T}"/>s are equal.
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
Expand All @@ -146,7 +146,7 @@ public static Task<Option<T>> NoneAsync() =>
left.Equals(right);

/// <summary>
/// Returns true if the specified Options are not equal.
/// Returns true if the specified <see cref="Option{T}"/>s are not equal.
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
Expand All @@ -155,15 +155,15 @@ public static Task<Option<T>> NoneAsync() =>
!(left == right);

/// <summary>
/// Returns true if the specified Options are equal.
/// Returns true if the specified <see cref="Option{T}"/>s are equal.
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object? obj) =>
obj is Option<T> o && Equals(o);

/// <summary>
/// Returns true if the specified Options are equal.
/// Returns true if the specified <see cref="Option{T}"/>s are equal.
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
Expand All @@ -180,7 +180,7 @@ public readonly bool Equals(Option<T> other) =>
);

/// <summary>
/// Returns the hash code of the Option.
/// Returns the hash code of the <see cref="Option{T}"/>.
/// </summary>
/// <returns></returns>
public override int GetHashCode() =>
Expand All @@ -189,7 +189,7 @@ public override int GetHashCode() =>
none: () => 0);

/// <summary>
/// Returns the string representation of the Option.
/// Returns the string representation of the <see cref="Option{T}"/>.
/// </summary>
/// <returns></returns>
public override string ToString() =>
Expand All @@ -199,12 +199,12 @@ public override string ToString() =>
}

/// <summary>
/// Extension methods to allow Option matching using
/// Extension methods to allow <see cref="Option{T}"/> matching using
/// </summary>
public static class OptionActionExtensions
{
/// <summary>
/// If Option is Some, evaluates the some delegate, otherwise evaluates
/// If <see cref="Option{T}"/> is Some, evaluates the some delegate, otherwise evaluates
/// the none delegate.
/// </summary>
/// <typeparam name="T"></typeparam>
Expand Down
Loading

0 comments on commit 2596a80

Please sign in to comment.