On Thursday, October 16, 2014 11:19:32 PM UTC+2, Tom Oram wrote:
>
> In Clojure, would you consider hiding the data behind a set of specialised
> functions to create, access and use it? Or would you just pass the
> primitive string/map/vector/whatever about and work on it directly?
>
Stuart Sierra recommends keeping ALL your state in a map and structure your
application as a chain of functions that take the map and return a new map.
It is a very good functional style because it is similar to the state monad
in Haskell.
;; Bad
(defn complex-process []
(let [a (get-component @global-state)
b (subprocess-one a)
c (subprocess-two a b)
d (subprocess-three a b c)]
(reset! global-state d)))
;; Good
(defn complex-process [state]
(-> state
subprocess-one
subprocess-two
subprocess-three))
So your customer would be a map in an array of customers in the state map.
Clojure has the functions update-in and similar to simplify this kind of
data manipulations. I saw it mentioned at
https://programmers.stackexchange.com/questions/208154/everything-is-a-map-am-i-doing-this-right
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.