November 2019
Intermediate to advanced
56 pages
37m
English
The reality of professional programming is that most of the job is about data transformation. This necessary function often cries out for an abstraction. For example, if you create or consume a web service, chances are you will need to convert Clojure data to JSON data.
I could implement a data transformation abstraction with a plain function:
1 (ns stadig.json)
2
3 (defn convert
4 [obj]
5 (cond
6 (string? obj) obj
7 (map? obj) (str (reduce-kv (fn [s k v]
8 (str s (convert k) " : " (convert v) " "))
9 "{"
10 obj)
11 "}")
12 ,,,))
…a multimethod:
1 (ns stadig.json)
2
3 (defmulti convert type) ...