FunSharp.Common/UpdateExtensions.cs
//--------------------------------------------------
/// <summary>
/// Run the selector that matches the case of
/// <paramref name="update" />.
/// </summary>
Run the selector that matches the case of
.
Run the selector that matches the case of .
[NotNull]
        public static TResult Match<T, TResult>(
            [NotNull] this Update<T> update,
            [NotNull] Func<T, TResult> setSelector,
            [NotNull] Func<TResult> ignoreSelector,
            [NotNull] Func<TResult> clearSelector)
        {
            if (update is null) throw new ArgumentNullException(nameof(update));
            if (setSelector is null) throw new ArgumentNullException(nameof(setSelector));
            if (ignoreSelector is null) throw new ArgumentNullException(nameof(ignoreSelector));
            if (clearSelector is null) throw new ArgumentNullException(nameof(clearSelector));
            switch (update)
            {
                case UpdateIgnore<T> _: return ignoreSelector();
                case UpdateClear<T> _: return clearSelector();
                case UpdateSet<T> someUpdate: return setSelector(someUpdate.Value);
                default: throw new ArgumentOutOfRangeException(nameof(update));
            }
        }
[ NotNull ] public static TResult Match < T , TResult > ( [ NotNull ] this Update < T > update , [ NotNull ] Func < T , TResult > setSelector , [ NotNull ] Func < TResult > ignoreSelector , [ NotNull ] Func < TResult > clearSelector ) { if ( update is null ) throw new ArgumentNullException ( nameof ( update ) ) ; if ( setSelector is null ) throw new ArgumentNullException ( nameof ( setSelector ) ) ; if ( ignoreSelector is null ) throw new ArgumentNullException ( nameof ( ignoreSelector ) ) ; if ( clearSelector is null ) throw new ArgumentNullException ( nameof ( clearSelector ) ) ; switch ( update ) { case UpdateIgnore < T > _ : return ignoreSelector ( ) ; case UpdateClear < T > _ : return clearSelector ( ) ; case UpdateSet < T > someUpdate : return setSelector ( someUpdate . Value ) ; default : throw new ArgumentOutOfRangeException ( nameof ( update ) ) ; } }
Run the selector that matches the case of
.
Run the selector that matches the case of .
this
[NotNull]
Func<T, TResult>
[NotNull]
Func<TResult>
[NotNull]