Skip to content

Instantly share code, notes, and snippets.

@ericnormand
Last active November 12, 2025 20:36
Show Gist options
  • Select an option

  • Save ericnormand/e2a506c9f5cc168ed818791498804167 to your computer and use it in GitHub Desktop.

Select an option

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.
@ezmiller
Copy link

ezmiller commented Nov 12, 2025

(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)))))

@joshuamzm
Copy link

(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.

@KJBrock
Copy link

KJBrock commented Nov 12, 2025

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.

@emil0r
Copy link

emil0r commented Nov 12, 2025

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)
])

@kettroni
Copy link

kettroni commented Nov 12, 2025

;; 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)

@recia-r
Copy link

recia-r commented Nov 12, 2025

;;# 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment