Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Item (name : string, price : float) =
- member this.Price =
- price;
- member this.Name =
- name;
- type Customer (shoppingList : list<Item>, inBasket : list<Item>) =
- member this.ShoppingList =
- shoppingList;
- member this.Shop =
- this.AddItem(shoppingList.Head);
- member this.AddItem(item : Item) =
- new Customer(List.filter (fun x -> x <> item) shoppingList, List.append inBasket [item]);
- member this.Done =
- shoppingList.IsEmpty
- type Checkout (customers : list<Customer>) =
- member this.AddCustomer(customer : Customer) =
- Checkout(List.append customers [customer]);
- member this.Tick =
- // todo - remove items from customer basket, remove customer when empty
- Checkout(customers);
- type Supermarket (checkouts : list<Checkout>, customers : list<Customer>) =
- member this.Tick =
- let tickedCustomers = List.map (fun (x:Customer) -> x.Shop) customers;
- let tickedCheckouts = List.map (fun (x:Checkout) -> x.Tick) checkouts;
- let doneCustomers = List.filter (fun (x:Customer) -> x.Done) tickedCustomers;
- let notDoneCustomers = List.filter (fun (x:Customer) -> not x.Done) tickedCustomers;
- let filledCheckouts = this.SendCustomersToCheckouts(doneCustomers, tickedCheckouts);
- Supermarket(filledCheckouts, notDoneCustomers);
- member this.SendCustomersToCheckouts (doneCustomers : list<Customer>, readyCheckouts : list<Checkout>) =
- // todo - add customers to checkouts
- readyCheckouts
- let rec simulate (supermarket : Supermarket) =
- simulate supermarket.Tick;
- let singleCustomerShoppingList = [Item("Fishycakes", 5.0); Item("Nommycakes", 7.0)];
- let singleCustomer = Customer(singleCustomerShoppingList, []);
- let singleCheckout = Checkout([]);
- let supermarket = Supermarket([singleCheckout], [singleCustomer]);
- simulate(supermarket);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement