Skip to content

Instantly share code, notes, and snippets.

@bsteuber
Created March 22, 2012 22:54
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 bsteuber/2165263 to your computer and use it in GitHub Desktop.
Save bsteuber/2165263 to your computer and use it in GitHub Desktop.
(defn replace-pred-once [pred replacement list]
(let [[bef
[elt & aft]] (split-with (complement pred)
list)]
(concat bef [replacement] aft)))
(comment (replace-pred-once #{5} :foo [1 2 3 4 5 6 7 8 5 3])
=> (1 2 3 4 :foo 6 7 8 5 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment