Skip to content

Instantly share code, notes, and snippets.

@ifesdjeen
Created June 24, 2013 12:52
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 ifesdjeen/5849817 to your computer and use it in GitHub Desktop.
Save ifesdjeen/5849817 to your computer and use it in GitHub Desktop.
Clojure string tail
(defn ^String head
"Returns the first n characters of s."
[n ^String s]
(if (> (count s) n)
s
(.substring s (- 0 n))))
(defn ^String tail
"Returns the last n characters of s."
[n ^String s]
(if (< (count s) n)
s
(.substring s (- (count s) n))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment