Пример #1
0
        public void OptionFilterWhenFalse()
        {
            Option <int> optionValue = 35;
            Option <int> result      = OptionModule.Filter(_isEven, optionValue);

            Assert.IsTrue(result.IsNone);
        }
Пример #2
0
        public void OptionFilterWhenTrue()
        {
            int          expected     = 36;
            Option <int> optionValue  = expected;
            Option <int> optionResult = OptionModule.Filter(_isEven, optionValue);
            int          result       = optionResult.Match(value => value, () => 0);


            Assert.AreEqual(expected, result);
        }
Пример #3
0
 /// <summary>
 /// Returns the <paramref name="option"/> if it <see cref="Option{T}.IsSome"/> and the <paramref name="predicate"/> return true when applied it.
 /// Otherwise, returns an <see cref="Option{T}.None()"/>.
 /// </summary>
 /// <typeparam name="T">The type of the option value.</typeparam>
 /// <param name="predicate">A function that evaluates whether the value contained in the option should remain, or be filtered out.</param>
 /// <param name="option">The input option.</param>
 /// <returns>
 /// Returns <paramref name="option"/> if the option <see cref="Option{T}.IsSome"/> and the <paramref name="predicate"/> function returns true.
 /// Otherwise, returns an <see cref="Option{T}.None()"/>.
 /// </returns>
 public static Option <T> Filter <T>(this Option <T> option, Func <T, bool> predicate)
 => OptionModule.Filter(predicate, option);