public void Should_execute_method_after_first_one_with_different_types()
        {
            Func <string, double> processor = sqrt.After(convert).After(parse);
            var result = processor("4");

            result.Should().Be(2);
        }
        internal static void TransformationForComposition()
        {
            // List<int> -> List<int>
            Func <List <int>, List <int> > removeAtWithIndex    = RemoveAt <int>(0);
            Func <List <int>, List <int> > findAllWithPredicate = FindAll <int>(int32 => int32 > 0);
            Func <List <int>, List <int> > reverse           = Reverse;
            Func <List <int>, List <int> > forEachWithAction = ForEach <int>(int32 => int32.WriteLine());
            Func <List <int>, List <int> > clear             = Clear;
            Func <List <int>, List <int> > addWithValue      = Add(1);

            Func <List <int>, List <int> > backwardComposition =
                addWithValue
                .After(clear)
                .After(forEachWithAction)
                .After(reverse)
                .After(findAllWithPredicate)
                .After(removeAtWithIndex);

            Func <List <int>, List <int> > forwardComposition =
                removeAtWithIndex
                .Then(findAllWithPredicate)
                .Then(reverse)
                .Then(forEachWithAction)
                .Then(clear)
                .Then(addWithValue);
        }
        public void Should_execute_Method_after_first_one()
        {
            // Act
            var result = appendWorld.After(appendHello)(string.Empty);

            result.Should().Be("HelloWorld");
        }
Exemplo n.º 4
0
        public static void Test()
        {
            Func <string, int> parse = int.Parse; // string -> int
            Func <int, int>    abs   = Math.Abs;  // int -> int

            Func <string, int> composition1 = abs.After(parse);
            Func <string, int> composition2 = Composition(abs, parse);
        }
Exemplo n.º 5
0
        public static void AfterTest()
        {
            Func <List <int>, int> length = x => x.Count;
            Func <int, int>        twice  = x => x * 2;

            Assert.Equal(6, twice.After(length)(new List <int> {
                1, 2, 3
            }));
        }
Exemplo n.º 6
0
        public void AfterWithUnaryAndNullaryFunctionsIsAliasForCompose()
        {
            Func <int, double> squareRoot = x => Math.Sqrt(x);
            Func <int>         nine       = () => 9;
            var squareRootOfNineE         = nine.ComposeReverse(squareRoot);

            var squareRootOfNineA = squareRoot.After(nine);

            Assert.That(squareRootOfNineA(), Is.EqualTo(squareRootOfNineE()));
        }
        internal static void Composition <T, TResult1, TResult2>(
            Func <TResult1, TResult2> second, // TResult1 -> TResult2
            Func <T, TResult1> first)         // T -> TResult1
        {
            Func <T, TResult2> composition;   // T -> TResult2

            composition = second.After(first);
            // Equivalent to:
            composition = first.Then(second);
        }
Exemplo n.º 8
0
        public void AfterWithUnaryFunctionsIsAliasForCompose()
        {
            Func <int, int>   square = x => x * x;
            Func <int[], int> sum    = a => a.Sum();
            var squareOfSumE         = square.Compose(sum);
            var input = new[] { 1, 2, 3, 4 };

            var squareOfSumA = square.After(sum);

            Assert.That(squareOfSumA(input), Is.EqualTo(squareOfSumE(input)));
        }
Exemplo n.º 9
0
        internal static void Composite()
        {
            Func <double, double> sqrt = Math.Sqrt;
            Func <double, double> abs  = Math.Abs;

            Func <double, double> absSqrt1 = sqrt.After(abs);

            Trace.WriteLine(absSqrt1(-2D)); // 1.4142135623731

            Func <double, double> absSqrt2 = abs.Before(sqrt);

            Trace.WriteLine(absSqrt2(-2D)); // 1.4142135623731
        }
Exemplo n.º 10
0
            public void should_subtract_time_from_the_specified_date()
            {
                var actualDirection = TimeDirection.Past;
                var referenceDate   = new DateTime(1976, 1, 1);

                Func <DateTime, int, DateTime> function =
                    (d, t) => { actualDirection = t; return(d); };

                var actualDate = function.After(referenceDate);

                Check.That(actualDirection).IsEqualTo(TimeDirection.Future);
                Check.That(actualDate).IsEqualTo(referenceDate);
            }
Exemplo n.º 11
0
        internal static void Compose()
        {
            Func <string, int>    parse   = int.Parse;        // string -> int
            Func <int, int>       abs     = Math.Abs;         // int -> int
            Func <int, double>    convert = Convert.ToDouble; // int -> double
            Func <double, double> sqrt    = Math.Sqrt;        // double -> double

            // string -> double
            Func <string, double> composition1 = sqrt.After(convert).After(abs).After(parse);

            composition1("-2.0").WriteLine(); // 1.4142135623731

            // string -> double
            Func <string, double> composition2 = parse.Then(abs).Then(convert).Then(sqrt);

            composition2("-2.0").WriteLine(); // 1.4142135623731
        }
Exemplo n.º 12
0
        internal static void BackwardCompositionForwardComposition()
        {
            Func <string, int>    parse   = int.Parse;        // string -> int
            Func <int, int>       abs     = Math.Abs;         // int -> int
            Func <int, double>    convert = Convert.ToDouble; // int -> double
            Func <double, double> sqrt    = Math.Sqrt;        // double -> double

            // string -> double
            Func <string, double> backwardComposition = sqrt.After(convert).After(abs).After(parse);

            backwardComposition("-2").WriteLine(); // 1.4142135623731

            // string -> double
            Func <string, double> forwardComposition = parse.Then(abs).Then(convert).Then(sqrt);

            forwardComposition("-2").WriteLine(); // 1.4142135623731
        }
Exemplo n.º 13
0
 /// <inheritdoc />
 public Func <T, T> Op(Func <T, T> x, Func <T, T> y) => x.After(y);