Пример #1
0
        public void EitherFoldBackWhenLeft()
        {
            int state    = 10;
            int expected = 10;
            Either <string, int> either = "10";
            int result =
                EitherModule.FoldBack(
                    (right, _state) => right + _state,
                    (left, _state) => _state,
                    either,
                    state);

            Assert.AreEqual(expected, result);
        }
Пример #2
0
 /// <summary>
 /// Creates a new <typeparamref name="TState"/> value by applying the given folder functions
 /// to <see cref="Either{TLeft, TRight}"/> value and <paramref name="state"/>.
 /// </summary>
 /// <typeparam name="TLeft">The type of the left value.</typeparam>
 /// <typeparam name="TRight">The type of the right value.</typeparam>
 /// <typeparam name="TState">The type of initial and final states</typeparam>
 /// <param name="folderWhenLeft">The function to transform either value from the input <paramref name="either"/> to a new state value.</param>
 /// <param name="folderWhenRight">The function to transform either value from the input <paramref name="either"/> to a new state value.</param>
 /// <param name="state">The initial state.</param>
 /// <param name="either">the input either.</param>
 /// <returns>
 /// Returns a new <typeparamref name="TState"/> value by applying the given folder functions
 /// to <see cref="Either{TLeft, TRight}"/> value and <paramref name="state"/>
 /// </returns>
 public static TState FoldBack <TLeft, TRight, TState>(this Either <TLeft, TRight> either, Func <TRight, TState, TState> folderWhenRight, Func <TLeft, TState, TState> folderWhenLeft, TState state)
 => EitherModule.FoldBack(folderWhenRight, folderWhenLeft, either, state);