55
66namespace RustyOptions ;
77
8- // TODO: Match that returns void?
98// TODO: OptionNumber that implements INumber?
109// TODO: Async?
1110
@@ -66,8 +65,8 @@ public bool IsSome([MaybeNullWhen(false)] out T value)
6665 /// of the <see cref="Option{T}"/>.
6766 /// </summary>
6867 /// <typeparam name="T2">The return type of the given functions.</typeparam>
69- /// <param name="onSome">The function to pass the value to, if the result is <c>Ok </c>.</param>
70- /// <param name="onNone">The function to pass the error value to, if the result is <c>Err </c>.</param>
68+ /// <param name="onSome">The function to pass the value to, if the option is <c>Some </c>.</param>
69+ /// <param name="onNone">The function to call if the option is <c>None </c>.</param>
7170 /// <returns>The value returned by the called function.</returns>
7271 /// <exception cref="System.ArgumentNullException">Thrown if either <paramref name="onSome"/> or <paramref name="onNone"/> is null.</exception>
7372 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
@@ -78,6 +77,24 @@ public T2 Match<T2>(Func<T, T2> onSome, Func<T2> onNone)
7877 return _isSome ? onSome ( _value ) : onNone ( ) ;
7978 }
8079
80+ /// <summary>
81+ /// If the option is <c>Some</c>, passes the contained value to the <paramref name="onSome"/> function.
82+ /// Otherwise calls the <paramref name="onNone"/> function.
83+ /// </summary>
84+ /// <param name="onSome">The function to call with the contained <c>Some</c> value, if any.</param>
85+ /// <param name="onNone">The function to call if the option is <c>None</c>.</param>
86+ /// <exception cref="System.ArgumentNullException">Thrown if either <paramref name="onSome"/> or <paramref name="onNone"/> is null.</exception>
87+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
88+ public void Match ( Action < T > onSome , Action onNone )
89+ {
90+ ThrowIfNull ( onSome ) ;
91+ ThrowIfNull ( onNone ) ;
92+ if ( _isSome )
93+ onSome ( _value ) ;
94+ else
95+ onNone ( ) ;
96+ }
97+
8198 /// <summary>
8299 /// Returns the contained <c>Some</c> value, or throws an <see cref="InvalidOperationException"/>
83100 /// if the value is <c>None</c>.
0 commit comments