Skip to content

Instantly share code, notes, and snippets.

@whilo
Created November 22, 2013 01:30
Show Gist options
  • Save whilo/7593262 to your computer and use it in GitHub Desktop.
Save whilo/7593262 to your computer and use it in GitHub Desktop.
Clojure like functional data functions for hy sketch.
(import [pysistence [make_list make_dict]])
(defn atom [init-val])
(defn swap! [atom fn])
(defn massoc [as k v]
(kwapply (as.using) {k v}))
(defn assoc-in [as ks v]
(if (= (len ks) 1)
(massoc as (first ks) v)
(massoc as (first ks)
(assoc-in (get as (first ks)) (rest ks) v))))
(defn get-in [as ks]
(if (= (len ks) 1)
(get as (first ks))
(get-in (get as (first ks)) (rest ks))))
(defn update-in [as ks f]
(let [[old (get-in as ks)]
[new (f old)]]
(assoc-in as ks new)))
;; (massoc (make-dict {:a 1}) :a 2)
;; (update-in (make-dict {:a (make-dict {:b 1})}) [:a :b] inc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment