FunSharp.Common/UpdateExtensions.cs
//--------------------------------------------------
/// <summary>
/// Produce an <see cref="Update{T}"/> with the value
/// in <paramref name="update" />, only if it passes
/// <paramref name="predicate" />.
/// </summary>
Produce an  with the value
in , only if it passes
.
Produce an with the value in only if it passes .
[NotNull]
        public static Update<T> Filter<T>(
            [NotNull] this Update<T> update,
            [NotNull] Func<T, bool> predicate)
        {
            if (update is null) throw new ArgumentNullException(nameof(update));
            if (predicate is null) throw new ArgumentNullException(nameof(predicate));
            switch (update)
            {
                case UpdateSet<T> someUpdate when predicate(someUpdate.Value):
                    return update;
                case UpdateSet<T> _:
                case UpdateIgnore<T> _:
                    return Update<T>.Ignore;
                case UpdateClear<T> _:
                    return Update<T>.Clear;
                default: throw new ArgumentOutOfRangeException(nameof(update));
            }
        }
[ NotNull ] public static Update < T > Filter < T > ( [ NotNull ] this Update < T > update , [ NotNull ] Func < T , bool > predicate ) { if ( update is null ) throw new ArgumentNullException ( nameof ( update ) ) ; if ( predicate is null ) throw new ArgumentNullException ( nameof ( predicate ) ) ; switch ( update ) { case UpdateSet < T > someUpdate when predicate ( someUpdate . Value ) : return update ; case UpdateSet < T > _ : case UpdateIgnore < T > _ : return Update < T > . Ignore ; case UpdateClear < T > _ : return Update < T > . Clear ; default : throw new ArgumentOutOfRangeException ( nameof ( update ) ) ; } }
Produce an  with the value
in , only if it passes
.
Produce an with the value in only if it passes .
this
[NotNull]
Func<T, bool>
[NotNull]