public static void RunSimpleMultiDemo() { Source source = new Source(); Destination dest = new Destination(); Arrow <Tuple <int, int>, int> multiplier = Op.Arr((Tuple <int, int> x) => x.Item1 * x.Item2); Arrow <int, int> square = Op.Arr((int x) => x * x); Func <int, int, int> add = (int x, int y) => x + y; Arrow <Tuple <int, int>, int> pythagoras = Op.And(square, square) .Unsplit(add) .Combine(Op.Arr((int x) => (int)Math.Sqrt(x))); BindingsManager.CreateBinding(BindingsManager.BindPoints(new BindPoint(source, "source"), new BindPoint(source, "multiplies")), pythagoras, BindingsManager.BindPoints(new BindPoint(dest, "result"))); source.multiplies = 2; source.source = 3; if (dest.result == pythagoras.Invoke(Tuple.Create(source.source, source.multiplies))) { Console.WriteLine("Multibindings in one direction work :)"); } else { Console.WriteLine("Ohnoes multibindings in one direction don't work"); } }
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); }
public static bool TestSub() { bool result = true; byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; byte[] out1 = { 1, 2, 3 }; result = Op.And(result, Op.SubBytes(data, 0, 3) == out1); byte[] out2 = { 4, 5, 6, 7, 8, 9 }; result = Op.And(result, Op.SubBytes(data, 3, 6) == out2); return(result); }
public static bool TestOp() { bool result = true; BigInteger integer = 15; byte b = Op.BigInt2Bytes(integer)[0]; result = Op.And(result, b == 15); BigInteger integer1 = 255; byte b1 = Op.BigInt2Bytes(integer1)[0]; result = Op.And(result, b == 255); int i = 2; string s = "c"; string o = s + i.ToString(); result = Op.And(result, o == "c2"); return(result); }