Skip to content

Instantly share code, notes, and snippets.

@timmc
Created March 3, 2011 17:09
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 timmc/853113 to your computer and use it in GitHub Desktop.
Save timmc/853113 to your computer and use it in GitHub Desktop.
(defn replace-1
"Replace the first x in coll such that (pred x) is true with (gen x).
Not tail-recursive."
[coll pred gen]
(if (seq coll)
(if (pred (first coll))
(conj (rest coll)
(gen (first coll)))
(conj (replace-1 (rest coll) pred gen)
(first coll)))
coll))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment