Skip to content

Instantly share code, notes, and snippets.

@lagenorhynque
Last active October 1, 2017 14:20
Show Gist options
  • Select an option

  • Save lagenorhynque/1c39e13c3946c175386505950e0efa67 to your computer and use it in GitHub Desktop.

Select an option

Save lagenorhynque/1c39e13c3946c175386505950e0efa67 to your computer and use it in GitHub Desktop.
user> (defn enum
([fst]
(iterate inc fst))
([fst snd]
(iterate #(+ % (- snd fst)) fst))
([fst snd lst]
(range fst (inc lst) (- snd fst))))
#'user/enum
user> (take 10 (enum 1)) ; take 10 [1..]
(1 2 3 4 5 6 7 8 9 10)
user> (take 10 (enum 1 3)) ; take 10 [1, 3..]
(1 3 5 7 9 11 13 15 17 19)
user> (enum 1 3 21) ; [1, 3..21]
(1 3 5 7 9 11 13 15 17 19 21)
user>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment