Beispiel #1
0
        public void OptionApplyWhenSomeFunctionSomeValue()
        {
            Option <Func <int, bool> > optionFunction = _isEven;
            Option <int>  optionValue  = 36;
            Option <bool> optionResult =
                OptionModule.Apply(optionFunction, optionValue);

            bool result = optionResult.Match(value => value, () => false);

            Assert.IsTrue(optionResult.IsSome && result);
        }
Beispiel #2
0
        public void OptionApplyWhenNoneFunctionNoneValue()
        {
            Option <Func <int, bool> > optionFunction = Option <Func <int, bool> > .None();

            Option <int> optionValue = Option <int> .None();

            Option <bool> optionResult =
                OptionModule.Apply(optionFunction, optionValue);

            bool result = optionResult.Match(value => value, () => false);

            Assert.IsTrue(optionResult.IsNone);
        }
Beispiel #3
0
 /// <summary>
 /// Creates a new <see cref="Option{T}"/> whose value is the result of applying the given <paramref name="applying"/> function
 /// to <see cref="Option{T}.Some(T)"/> value when both <paramref name="applying"/> and <paramref name="option"/> are <see cref="Option{T}.IsSome"/>.
 /// Otherwise returns an <see cref="Option{T}.None"/>.
 /// </summary>
 /// <typeparam name="T">The type of the option value.</typeparam>
 /// <typeparam name="TResult">The type of the value returned by <paramref name="applying"/> function.</typeparam>
 /// <param name="applying">The option function to transform option value from the input option.</param>
 /// <param name="option">The input option.</param>
 /// <returns>
 /// Returns a new <see cref="Option{T}"/> whose value is the result of applying the given <paramref name="applying"/> function
 /// to <see cref="Option{T}.Some(T)"/> value when both <paramref name="applying"/> and <paramref name="option"/> are <see cref="Option{T}.IsSome"/>.
 /// Otherwise returns an <see cref="Option{T}.None"/>.
 /// </returns>
 public static Option <TResult> Apply <T, TResult>(this Option <T> option, Option <Func <T, TResult> > applying)
 => OptionModule.Apply(applying, option);