Persistent map with lazily evaluated values for Clojure(Script).
zizz
(noun) A nap.
clojure.core/delay
.IFn
interface of persistent map.The zizzmap
can be used when large map need to be created but most of the map
keys will never be used. For example ring request map with multiple conversions
from HTTP request to Clojure data structure.
init
The macro init
is used to define map with delayed values.
(ns project.readme.core-01-init
(:require [strojure.zizzmap.core :as zizz]))
(def ^:private -map
(zizz/init {:a (do (println "Init") 1)}))
(get -map :a)
;Init
;=> 1
assoc*
The macro assoc*
returns map with delayed value at specified key.
(def ^:private -map1
(zizz/assoc* {} :a (do (println "Init") 1)))
(get -map1 :a)
;Init
;=> 1
(def ^:private -map2
(zizz/assoc* {}
:a (do (println "Init :a") 1)
:b (do (println "Init :b") 2)))
(get -map2 :b)
;Init
;=> 2
merge*
The function merge*
is like clojure.core/merge
but keeps pending values not
realized.
(ns project.readme.core-03-merge
(:require [strojure.zizzmap.core :as zizz]))
(def ^:private -merged
(zizz/merge* {:a 1}
(zizz/init {:b (do (println "Init") 2)})))
(get -merged :a)
;=> 1
(get -merged :b)
;Init
;=> 2
update*
The function update*
is like clojure.core/update
but delays application of
function f
to map value.
(ns project.readme.core-04-update
(:require [strojure.zizzmap.core :as zizz]))
;;; Update delayed value
(def ^:private -map1
(-> (zizz/init {:a (do (println "Init") 1)})
(zizz/update* :a inc)))
(get -map1 :a)
;Init
;=> 2
;;; Delayed update in standard map
(def ^:private -map2
(-> {:a 1}
(zizz/update* :a (fn [a]
(println "Update")
(inc a)))))
(get -map2 :a)
;Update
;=> 2
See some benchmarks here.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close