示例#1
0
        static void Main(string[] args)
        {
            Database data = new Database();

            ordersFromMicrosoft     = new ListOutput();
            ordersToCambridge       = new ListOutput();
            bulkOrders              = new ListOutput();
            averageOrdersToScotland = new IntOutput();

            BindingsManager.CreateBinding(
                data.GetBindPoint("orders"),
                ListArrow.Filter((Order x) => x.Supplier.Name == "Microsoft")
                .OrderBy((Order x, Order y) => x.Customer.Name.CompareTo(y.Customer.Name)),
                ordersFromMicrosoft.GetBindPoint("Orders"));

            BindingsManager.CreateBinding(
                data.GetBindPoint("orders"),
                ListArrow.Filter((Order x) => x.Customer.Location == "Cambridge")
                .OrderBy((Order x, Order y) => x.Customer.Name.CompareTo(y.Customer.Name)),
                ordersToCambridge.GetBindPoint("Orders"));

            BindingsManager.CreateBinding(
                data.GetBindPoint("orders"),
                ListArrow.Filter((Order x) => x.Volume > 30)
                .OrderBy((Order x, Order y) => x.Customer.Name.CompareTo(y.Customer.Name)),
                bulkOrders.GetBindPoint("Orders"));

            var averagingArrow = Op.Split <IEnumerable <int> >()
                                 .Combine(Op.And(
                                              ListArrow.Foldl((int x, int y) => x + y, 0),
                                              ListArrow.Foldl((int x, int y) => x + 1, 0)))
                                 .Unsplit((int total, int count) => total / count);

            BindingsManager.CreateBinding(
                data.GetBindPoint("orders"),
                ListArrow.Filter((Order x) => x.Customer.Location == "Glasgow" || x.Customer.Location == "Aberdeen")
                .Map((Order x) => x.Volume)
                .Combine(averagingArrow),
                averageOrdersToScotland.GetBindPoint("Result"));

            data.Initialise();

            PrintOutput("Orders from Microsoft", ordersFromMicrosoft);
            PrintOutput("Orders to Cambridge", ordersToCambridge);
            PrintOutput("Bulk orders", bulkOrders);
            Console.WriteLine("Average orders to Scotland: {0}", averageOrdersToScotland.Result);
            Console.WriteLine();

            IncreaseMoragsOrder(data);
            MoveBrendaToCambridge(data);
            MicrosoftTakeover(data);
        }
示例#2
0
        static void Main(string[] args)
        {
            Database data = new Database();
            ordersFromMicrosoft = new ListOutput();
            ordersToCambridge = new ListOutput();
            bulkOrders = new ListOutput();
            averageOrdersToScotland = new IntOutput();

            BindingsManager.CreateBinding(
                data.GetBindPoint("orders"),
                ListArrow.Filter((Order x) => x.Supplier.Name == "Microsoft")
                    .OrderBy((Order x, Order y) => x.Customer.Name.CompareTo(y.Customer.Name)),
                ordersFromMicrosoft.GetBindPoint("Orders"));

            BindingsManager.CreateBinding(
                data.GetBindPoint("orders"),
                ListArrow.Filter((Order x) => x.Customer.Location == "Cambridge")
                    .OrderBy((Order x, Order y) => x.Customer.Name.CompareTo(y.Customer.Name)),
                ordersToCambridge.GetBindPoint("Orders"));

            BindingsManager.CreateBinding(
                data.GetBindPoint("orders"),
                ListArrow.Filter((Order x) => x.Volume > 30)
                    .OrderBy((Order x, Order y) => x.Customer.Name.CompareTo(y.Customer.Name)),
                bulkOrders.GetBindPoint("Orders"));

            var averagingArrow = Op.Split<IEnumerable<int>>()
                .Combine(Op.And(
                        ListArrow.Foldl((int x, int y) => x + y, 0),
                        ListArrow.Foldl((int x, int y) => x + 1, 0)))
                    .Unsplit((int total, int count) => total / count);

            BindingsManager.CreateBinding(
                data.GetBindPoint("orders"),
                ListArrow.Filter((Order x) => x.Customer.Location == "Glasgow" || x.Customer.Location == "Aberdeen")
                    .Map((Order x) => x.Volume)
                    .Combine(averagingArrow),
                averageOrdersToScotland.GetBindPoint("Result"));

            data.Initialise();

            PrintOutput("Orders from Microsoft", ordersFromMicrosoft);
            PrintOutput("Orders to Cambridge", ordersToCambridge);
            PrintOutput("Bulk orders", bulkOrders);
            Console.WriteLine("Average orders to Scotland: {0}", averageOrdersToScotland.Result);
            Console.WriteLine();

            IncreaseMoragsOrder(data);
            MoveBrendaToCambridge(data);
            MicrosoftTakeover(data);
        }