Пример #1
0
        public void EitherFoldLeftWhenLeft()
        {
            string state                = "Hello";
            string expected             = "Hello World";
            Either <string, int> either = " World";
            string result               =
                EitherModule.FoldLeft(
                    (_state, left) => string.Concat(_state, left),
                    state,
                    either);

            Assert.AreEqual(expected, result);
        }
Пример #2
0
 /// <summary>
 /// Creates a new <typeparamref name="TState"/> value by applying the given <paramref name="folder"/> function
 /// to <paramref name="state"/> and <see cref="Either{TLeft, TRight}"/> value when <paramref name="either"/> <see cref="Either{TLeft, TRight}.IsLeft"/>.
 /// Otherwise, returns the <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="folder">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 <paramref name="state"/> and <see cref="Either{TLeft, TRight}"/> value <see cref="Either{TLeft, TRight}.IsLeft"/>.
 /// Otherwise, returns the input <paramref name="either"/>.
 /// </returns>
 public static TState FoldLeft <TLeft, TRight, TState>(this Either <TLeft, TRight> either, TState state, Func <TState, TLeft, TState> folder)
 => EitherModule.FoldLeft(folder, state, either);