-
-
Save ericnormand/e2a506c9f5cc168ed818791498804167 to your computer and use it in GitHub Desktop.
| # Coffee shop scenario | |
| Background: *This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.* | |
| Operation set: | |
| (defn create-order []) ;;=> Order | |
| (defn add-coffee [order coffee]) ;;=> Order | |
| (defn order-price [order]) ;;=> Price | |
| (defn remove-coffee [order coffee-index]) ;;=> Order | |
| (defn update-coffee [order coffee-index f & args]) ;;=> Order | |
| (defn submit-order [order]) ;;=> OrderID | |
| (defn create-coffee []) ;;=> Coffee | |
| (defn set-size [coffee size]) ;;=> Coffee | |
| (defn set-roast [coffee roast]) ;;=> Coffee | |
| (defn add-add-in [coffee add-in]) ;;=> Coffee | |
| (defn remove-add-in [coffee add-in]) ;;=> Coffee | |
| ;; Order | |
| ;; Price - maybe a number of cents? | |
| ;; Coffee-Index - ordinal number | |
| ;; OrderID - UUID?? | |
| ;; Coffee | |
| ;; Size - small | |
| ;; Roast - dark, medium | |
| ;; Add-In - almond-syrup, soy-milk | |
| Jill starts to order some coffee at the touchscreen. | |
| She adds a small, dark roast. | |
| Then she adds a large medium roast with double almond syrup. | |
| She adds a medium medium roast with two soy milk shots (the second one by | |
| accident). | |
| She reads the price and it's too expensive. | |
| So she removes the second coffee (the one with the almond syrup). | |
| Then she realizes the third coffee has two milk soy shots and she removes one. | |
| The price looks good, so she submits the order. |
;:: # Coffee shop scenario
;:: Background: *This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.*
;:: Jill starts to order
(defn start-order []) ; => Order
(def order)
;:: some coffee at the touchscreen.
(defn add-item [order item]) ; => Order with a Coffee Item
(def item)
(add-item order item)
;:: She adds a small, dark roast.
(defn add-item [order]) ; => Order with a Coffee Item with two Details
(def item)
(def detailed-item (add-detail item detail))
;:: Then she adds a large medium roast with double almond syrup.
(defn add-item [order]) ; => Order with two specific Coffees,
; the latter of which has three Details, one of which has a quantity of 2
(def item)
(def detailed-item (add-detail item detail detail-meta))
;:: She adds a medium medium roast with two soy milk shots (the second one by accident).
(defn add-item [order]) ; => Order with three specific Coffees,
; the latter of which again has three Details, one with a quantity of 2
;:: She reads the price and it's too expensive.
(defn calculate-price [order]) ; => BigDecimal
(calculate-price order)
; or maybe
(calculate-price order prices)
; ^ and a mapping would exist to allow pulling in prices for certain items/details
;:: So she removes the second coffee (the one with the almond syrup).
(defn remove-item [order item]) ; => nil, and how to identify the item is a consideration
(remove-item order item)
;:: Then she realizes the third coffee has two soy milk shots and she removes one.
(defn display-order [order]) ; => visual; depending on UI, might be how she notices
; Similar use of remove-item as above
(display-order order)
(remove-item order item)
;:: The price looks good, so she submits the order.
(defn submit-order [order]) ; => nil
(submit-order order);:: # Coffee shop scenario
;:: Background: *This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.*
;:: Jill starts to order
(defn start-order []) ; => Order
(def order)
;:: some coffee at the touchscreen.
(defn add-item [order item]) ; => Order with a Coffee Item
(def item)
(add-item order item)
;:: She adds a small, dark roast.
(defn add-item [order]) ; => Order with a Coffee Item with two Details
(def item)
(def detailed-item (add-detail item detail))
;:: Then she adds a large medium roast with double almond syrup.
(defn add-item [order]) ; => Order with two specific Coffees,
; the latter of which has three Details, one of which has a quantity of 2
(def item)
(def detailed-item (add-detail item detail detail-meta))
;:: She adds a medium medium roast with two soy milk shots (the second one by accident).
(defn add-item [order]) ; => Order with three specific Coffees,
; the latter of which again has three Details, one with a quantity of 2
;:: She reads the price and it's too expensive.
(defn calculate-price [order]) ; => BigDecimal
(calculate-price order)
; or maybe
(calculate-price order prices)
; ^ and a mapping would exist to allow pulling in prices for certain items/details
;:: So she removes the second coffee (the one with the almond syrup).
(defn remove-item [order item]) ; => nil, and how to identify the item is a consideration
(remove-item order item)
;:: Then she realizes the third coffee has two soy milk shots and she removes one.
(defn display-order [order]) ; => visual; depending on UI, might be how she notices
; Similar use of remove-item as above
(display-order order)
(remove-item order item)
;:: The price looks good, so she submits the order.
(defn submit-order [order]) ; => nil
(submit-order order)(let [order (create order)]
(-> order
(add-coffee (-> (create-coffee)
(set-size :small)
(set-roast :dark)))
(add-coffee (-> (create-coffee)
(set-size :large)
(set-road :medium)
(add-add-in :almond-syrup 2)))))
(ns user)
;# Coffee shop scenario
;
;Background: *This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.*
;
;Operation set:
(defn create-order []) ;;=> order
(defn add-coffee [order & {:keys [size]}]) ;;=> order
(defn change-coffee [order coffee-id & {:keys [size addons]}]) ;;=> order
(defn add-coffee [order & {:keys [size addons]}]) ;;=> order
(defn remove-coffee [order coffee-id]) ;;=> order
(defn change-coffee [order coffee-id & {:keys [addons]}]) ;;=> order
(defn submit-order [order-id]) ;;=> order
;; Order
;; Price - maybe a number of cents?
;; Coffee-Index - ordinal number
;; OrderID - UUID??
;; Coffee
;; Size - small
;; Roast - dark, medium
;; Add-In - almond-syrup, soy-milk
(def order (create-order))
;Jill starts to order some coffee at the touchscreen.
(def order (add-coffee order :size :small, :roast :dark))
;She adds a small, dark roast.
(def order (add-coffee order :size :large-medium, :addons [{:quantity 2, :type :syrup, :flavor :almond}]))
;Then she adds a large medium roast with double almond syrup.
(def order (add-coffee order :size :medium-medium, :addons [{:quantity 2, :type :soy-milk}]))
;She adds a medium medium roast with two soy milk shots (the second one by accident).
(defn order-price [order]) ;; price
(def current-price (order-price order))
;She reads the price and it's too expensive.
(def order (remove-coffee order :oops-no-coffee-id))
;So she removes the second coffee (the one with the almond syrup).
(def order (change-coffee order :other-missed-id :addons [{:quantity 1, :type :soy-mil}]))
;Then she realizes the third coffee has two milk soy shots and she removes one.
(submit-order (:order-id order))
;The price looks good, so she submits the order.Coffee shop scenario
Background: This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.
Operation set:
(defn create-order []) ;;=> Order
(defn add-coffee [order coffee]) ;;=> Order
(defn order-price [order]) ;;=> Price
(defn remove-coffee [order coffee-index]) ;;=> Order
(defn update-coffee [order coffee-index f & args]) ;;=> Order
(defn submit-order [order]) ;;=> OrderID
(defn create-coffee []) ;;=> Coffee
(defn set-size [coffee size]) ;;=> Coffee
(defn set-roast [coffee roast]) ;;=> Coffee
(defn add-add-in [coffee add-in]) ;;=> Coffee
(defn remove-add-in [coffee add-in]) ;;=> Coffee
;; Order
;; Price - maybe a number of cents?
;; Coffee-Index - ordinal number
;; OrderID - UUID??
;; Coffee
;; Size - small
;; Roast - dark, medium
;; Add-In - almond-syrup, soy-milk
Jill starts to order some coffee at the touchscreen.
(def order (create-order))
She adds a small, dark roast.
(def coffee (-> (create-coffee)
(set-size :small)
(set-roast :dark)))
(add-coffee order coffee)
Then she adds a large medium roast with double almond syrup.
(def coffee (-> (create-coffee)
(set-size :large)
(set-roast :medium)
(add-add-in :almond-syrup)
(add-add-in :almond-syrup))
(add-coffee order coffee)
She adds a medium medium roast with two soy milk shots (the second one by
accident).
(def coffee (-> (create-coffee)
(set-size :medium)
(set-roast :medium)
(add-add-in :soy-milk)
(add-add-in :soy-milk))
(add-coffee order coffee)
She reads the price and it's too expensive.
So she removes the second coffee (the one with the almond syrup).
(def order (remove-coffee order 1))
Then she realizes the third coffee has two milk soy shots and she removes one.
The price looks good, so she submits the order.
Coffee shop scenario
Background: This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.
Operation set:
(defn create-order []) ;;=> Order
(defn add-coffee [order coffee]) ;;=> Order
(defn order-price [order]) ;;=> Price
(defn remove-coffee [order coffee-index]) ;;=> Order
(defn update-coffee [order coffee-index f & args]) ;;=> Order
(defn submit-order [order]) ;;=> OrderID
(defn create-coffee []) ;;=> Coffee
(defn set-size [coffee size]) ;;=> Coffee
(defn set-roast [coffee roast]) ;;=> Coffee
(defn add-add-in [coffee add-in]) ;;=> Coffee
(defn remove-add-in [coffee add-in]) ;;=> Coffee
;; Order
;; Price - maybe a number of cents?
;; Coffee-Index - ordinal number
;; OrderID - UUID??
;; Coffee
;; Size - small
;; Roast - dark, medium
;; Add-In - almond-syrup, soy-milk
Jill starts to order some coffee at the touchscreen.
She adds a small, dark roast.
Then she adds a large medium roast with double almond syrup.
She adds a medium medium roast with two soy milk shots (the second one by
accident).
She reads the price and it's too expensive.
So she removes the second coffee (the one with the almond syrup).
Then she realizes the third coffee has two milk soy shots and she removes one.
The price looks good, so she submits the order.
;; assuming pure functions
(let [order (create-order)
order (add-coffee order (create-coffee))
order (update-coffee order 0 set-size :small)
order (update-coffee order 0 set-roast :dark)
order (add-coffee order (create-coffee))
order (update-coffee order 1 set-size :large)
order (update-coffee order 1 set-roast :medium)
order (update-coffee order 1 add-add-in :almond-syrup)
order (update-coffee order 1 add-add-in :almond-syrup)
order (add-coffee order (create-coffee))
order (update-coffee order 2 set-size :medium)
order (update-coffee order 2 set-roast :medium)
order (update-coffee order 2 add-add-in :soy-milk)
order (update-coffee order 2 add-add-in :soy-milk)
price (order-price order)
order (remove-coffee order 1)
order (update-coffee order 1 remove-add-in :soy-milk)
price (order-price order)
order-id (submit-order order)
])
;; Jill starts to order some coffee at the touchscreen.
(-> (create-order)
;; She adds a small, dark roast.
(add-coffee (-> (create-coffee)
(set-size :small)
(set-roast :dark)))
;; Then she adds a large medium roast with double almond syrup.
(add-coffee (-> (create-coffee)
(set-size :large)
(set-roast :medium)))
;; She adds a medium medium roast with two soy milk shots (the second one by
;; accident).
(add-coffee (-> (create-coffee)
(set-size :medium)
(set-roast :medium)
(add-add-in :soy-milk-shot)
(add-add-in :soy-milk-shot)))
;; She reads the price and it's too expensive.
(#((assert (> (order-price %) <big-num>))
%))
;; So she removes the second coffee (the one with the almond syrup).
(remove-coffee 1)
;; Then she realizes the third coffee has two milk soy shots and she removes one.
(update-coffee 2 remove-add-in <coffee-3> :soy-milk-shot)
;; The price looks good, so she submits the order.
(#((assert (= (order-price %) <good-num>))
%))
submit-order)
;;# Coffee shop scenario
;;Background: This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.
;; Operation set:
(defn create-order []) ;;=> Order
(defn add-coffee [order coffee]) ;;=> Order
(defn order-price [order]) ;;=> Price
(defn remove-coffee [order coffee-index]) ;;=> Order
(defn update-coffee [order coffee-index f & args]) ;;=> Order
(defn submit-order [order]) ;;=> OrderID
(defn create-coffee []) ;;=> Coffee
(defn set-size [coffee size]) ;;=> Coffee
(defn set-roast [coffee roast]) ;;=> Coffee
(defn add-add-in [coffee add-in]) ;;=> Coffee
(defn remove-add-in [coffee add-in]) ;;=> Coffee
;; Order
;; Price - maybe a number of cents?
;; Coffee-Index - ordinal number
;; OrderID - UUID??
;; Coffee
;; Size - small
;; Roast - dark, medium
;; Add-In - almond-syrup, soy-milk
;;Jill starts to order some coffee at the touchscreen.
(def order (create-order))
;;She adds a small, dark roast.
(def coffee (create-coffee))
(def coffee (set-size coffee :small))
(def coffee (set-roast coffee :dark))
(def order (add-item-to-order coffee)) ;; ;; will give added item an id and will set coffee to base coffee
;;Then she adds a large medium roast with double almond syrup.
(def coffee (set-size coffee :large))
(def coffee (set-roast coffee :medium))
(def coffee (add-add-in coffee :almond-syrup))
(def coffee (add-add-in coffee :almond-syrup))
(def order (add-coffee order coffee))
;;She adds a medium medium roast with two soy milk shots (the second one by
;;accident).
(def coffee (set-size coffee :medium))
(def coffee (set-roast coffee :medium))
(def coffee (add-add-in coffee :soy-milk))
(def coffee (add-add-in coffee :soy-milk))
(def order (add-coffee order coffee))
;;She reads the price and it's too expensive.
;;So she removes the second coffee (the one with the almond syrup).
(def order (remove-coffee order item-id))
;;Then she realizes the third coffee has two milk soy shots and she removes one.
(def order (update-coffee order item-id remove-add-in :soy-milk))
;;The price looks good, so she submits the order.
;;TODO
Coffee shop scenario
Background: This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.
Operation set:
(defn create-order []) ;;=> Order
(defn add-coffee [order coffee]) ;;=> Order
(defn order-price [order]) ;;=> Price
(defn remove-coffee [order coffee-index]) ;;=> Order
(defn update-coffee [order coffee-index f & args]) ;;=> Order
(defn submit-order [order]) ;;=> OrderID
(defn create-coffee []) ;;=> Coffee
(defn set-size [coffee size]) ;;=> Coffee
(defn set-roast [coffee roast]) ;;=> Coffee
(defn add-add-in [coffee add-in]) ;;=> Coffee
(defn remove-add-in [coffee add-in]) ;;=> Coffee
;; Order
;; Price - maybe a number of cents?
;; Coffee-Index - ordinal number
;; OrderID - UUID??
;; Coffee
;; Size - small
;; Roast - dark, medium
;; Add-In - almond-syrup, soy-milk
Jill starts to order some coffee at the touchscreen.
(def order (create-order))
She adds a small, dark roast.
(def coffee (create-coffee))
(def coffee (set-size coffee :small))
(def coffee (set-roast coffee :dark))
(def oder (add-coffee order coffee))
Then she adds a large medium roast with double almond syrup.
(def coffee2 (create-coffee))
(def coffee2 (set-size coffee2 :large))
(def coffee2 (set-roast coffee2 :medium))
(def coffee2 (add-add-in coffee2 :almond-syrup))
(def coffee2 (add-add-in coffee2 :almond-syrup))
(def order (add-coffee order coffee2))
She adds a medium medium roast with two soy milk shots (the second one by
accident).
(def coffee3 (create-coffee))
(def coffee3 (set-size coffee3 :medium))
(def coffee3 (set-roast coffee3 :medium))
(def coffee3 (add-add-in coffee3 :soy-milk-shot))
(def coffee3 (add-add-in coffee3 :soy-milk-shot))
(def order (add-coffee order coffee3))
She reads the price and it's too expensive.
(def price (order-price order))
So she removes the second coffee (the one with the almond syrup).
(def order (remove-coffee order 1))
Then she realizes the third coffee has two milk soy shots and she removes one.
(def order (update-coffee order 1 remove-add-in :soy-milk-shot))
The price looks good, so she submits the order.
(def price (order-price order))
(def order-id (submit-order order))