Skip to content

Instantly share code, notes, and snippets.

@luxbock

luxbock/REST.clj Secret

Last active June 17, 2016 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luxbock/55ea567166081af107fd7a22582bf8c2 to your computer and use it in GitHub Desktop.
Save luxbock/55ea567166081af107fd7a22582bf8c2 to your computer and use it in GitHub Desktop.
(defnav REST []
(select* [this coll next-fn]
(next-fn
(if (vector? coll)
(subvec coll 1)
(rest coll))))
(transform* [this coll next-fn]
(if (seq? coll)
(cons (first coll)
(next-fn (rest coll)))
(into (conj (empty coll) (first coll))
(next-fn (rest coll))))))
(select-one REST [1 2 3 4 5]) ;; => [2 3 4 5]
(transform [REST ALL] inc [1 2 3 4 5]) ;; => [1 3 4 5 6]
(transform [REST ALL] inc #{1 2 3}) ;; => #{1 4 3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment