Skip to content

Instantly share code, notes, and snippets.

@fogus
Created February 17, 2011 14:34
Show Gist options
  • Select an option

  • Save fogus/831830 to your computer and use it in GitHub Desktop.

Select an option

Save fogus/831830 to your computer and use it in GitHub Desktop.
(ns whee
(:refer-clojure :exclude [conj]))
(defprotocol Q
(conj [q elem]))
(extend-type clojure.lang.PersistentQueue
Q
(conj [this elem]
(if (>= (count this) 3)
this
(clojure.core/conj this elem))))
(-> clojure.lang.PersistentQueue/EMPTY
(conj :a)
(conj :b)
(conj :c)
pop
(conj :d)
(conj :z)
seq)
;=> (:b :c :d)
(ns yay
(:refer whee))
(-> clojure.lang.PersistentQueue/EMPTY
(conj :a)
(conj :b)
(conj :c)
pop
(conj :d)
(conj :z)
seq)
;=> (:b :c :d)
(-> clojure.lang.PersistentQueue/EMPTY
(clojure.core/conj :a)
(clojure.core/conj :b)
(clojure.core/conj :c)
pop
(clojure.core/conj :d)
(clojure.core/conj :z)
seq)
;=> (:b :c :d :z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment