Skip to content

Instantly share code, notes, and snippets.

@statianzo
Created February 19, 2010 23:49
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 statianzo/309371 to your computer and use it in GitHub Desktop.
Save statianzo/309371 to your computer and use it in GitHub Desktop.
(defn ellipsize [length text]
(let [words (take length (split #"\W+" text))]
(str (join " " words ) "...")))
(defn indexed [coll] (map vector (iterate inc 0) coll))
(defn index-filter [pred coll]
(when pred
(for [[idx elt] (indexed coll) :when (pred elt)] idx)))
(defn index-of-any [pred coll]
(first (index-filter pred coll)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment