コード例 #1
0
        public void OptionBindWhenNone()
        {
            Option <int> optionValue = Option <int> .None();

            Option <int> optionResult = OptionModule.Bind(_squareWhenEven, optionValue);

            Assert.IsTrue(optionResult.IsNone);
        }
コード例 #2
0
        public void OptionBindWhenSomeTrue()
        {
            int          expected     = 36;
            Option <int> optionValue  = 6;
            Option <int> optionResult = OptionModule.Bind(_squareWhenEven, optionValue);
            int          result       = optionResult.Match(value => value, () => 0);

            Assert.AreEqual(expected, result);
        }
コード例 #3
0
 /// <summary>
 /// Creates a new <see cref="Option{T}"/> whose value is the result of applying the given <paramref name="binder"/> function
 /// to <paramref name="option"/> value.
 /// </summary>
 /// <typeparam name="T">The type of the option value.</typeparam>
 /// <typeparam name="TResult">The type of the option value returned by <paramref name="binder"/> function.</typeparam>
 /// <param name="binder">The function to transform option value from the input option to a new <see cref="Option{T}"/>.</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="binder"/> function
 /// to <paramref name="option"/> value.
 /// </returns>
 public static Option <TResult> Bind <T, TResult>(this Option <T> option, Func <T, Option <TResult> > binder)
 => OptionModule.Bind(binder, option);