Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
23 lines (16 sloc) 704 Bytes
(ns org.acooke.lab.state)
; this is related to
; the problem is:
; - there is a "state" which must be passed to a series of operations.
; - each operation returns some value and a new state
; - how do we sequence a series of operations without duplicating code?
; to see the code below in use, visit the associated test
(defn fold-over-state [state functions]
(reduce (fn [[acc state] f]
(let [[result state] (f state)]
[(conj acc result) state]))
[[] state] functions))
(defn fold-over [state functions]
(let [[acc state] (fold-over-state state functions)]