Skip to content

Instantly share code, notes, and snippets.

@raven-rock
Created November 30, 2017 09:29
Show Gist options
  • Save raven-rock/3433e8893442b1d8372708f2d829d6ab to your computer and use it in GitHub Desktop.
Save raven-rock/3433e8893442b1d8372708f2d829d6ab to your computer and use it in GitHub Desktop.
Clojure inclusive-range function
(defn inclusive-range
"Like range, but STOP (when defined) is inclusive. Leads to simpler code
without all the inc'ing etc. E.g.,
(inclusive-range 1 5) #=> (1 2 3 4 5)"
([] (range))
([stop] (range (inc stop)))
([start stop] (range start (inc stop)))
([start stop step] (range start (inc stop) step)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment