Skip to content

Instantly share code, notes, and snippets.

@ray1729
Created December 9, 2016 08:57
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 ray1729/9c4028f11fc56c6e61002ccc84e63826 to your computer and use it in GitHub Desktop.
Save ray1729/9c4028f11fc56c6e61002ccc84e63826 to your computer and use it in GitHub Desktop.
Insert before/after pred implemeted with split-with
(defn insert-after
[pred coll x]
(let [[before after] (split-with (complement pred) coll)]
(concat before (take 1 after) x (drop 1 after))))
(defn insert-before
[pred coll x]
(let [[before after] (split-with (complement pred) coll)]
(concat before x after)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment