コード例 #1
0
        public void ComposeMultipleUnaryFunctions()
        {
            Func <int, int> add1       = x => x + 1;
            Func <int, int> times2     = x => x * 2;
            Func <int, int> square     = x => x * x;
            Func <int, int> subtract10 = x => x - 10;

            Func <int, int> expectedComposed = x => (((x - 10) * (x - 10)) * 2) + 1;

            Func <int, int> composed = Fn.Compose(add1, times2, square, subtract10);

            Assert.That(composed(12), Is.EqualTo(expectedComposed(12)));
            Assert.That(composed(12), Is.EqualTo(9));
        }