Skip to content

Instantly share code, notes, and snippets.

@fehrenbach
Created April 3, 2010 16:43
Show Gist options
  • Select an option

  • Save fehrenbach/354668 to your computer and use it in GitHub Desktop.

Select an option

Save fehrenbach/354668 to your computer and use it in GitHub Desktop.
(deftype Element [data start end] :as this
clojure.lang.Associative
(assoc [key value]
(apply (fn [data start end]
(Element. data start end))
(vals (assoc {:data (:data this)
:start (:start this)
:end (:end this)}
key value)))))
;; much better:
(deftype Element [data start end]
clojure.lang.IPersistentMap)
@fehrenbach

Copy link
Copy Markdown
Author

(assoc (Element "bla" 23 42) :data "blubb") => #:Element{:data "blubb", :start 23, :end 42}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment