Skip to content

Instantly share code, notes, and snippets.

@devn
Created April 1, 2010 15:59
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 devn/351984 to your computer and use it in GitHub Desktop.
Save devn/351984 to your computer and use it in GitHub Desktop.
(defn truncate
"A one off truncation function which takes a coll in the form of \"[:a, :b]\". Provided a [t]runcation length (in characters), it will truncate :a or :b and supply a new \"[\":a...\", \":b...\"]\"."
[coll t]
(let [c coll
ct (first c)
rt (second c)]
[(if (>= (count ct) t)
(apply str (take t ct) "...")
ct)
(if (>= (count rt) t)
(apply str (take t rt) "...")
rt)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment