Skip to content

Instantly share code, notes, and snippets.

@fogus
Created January 26, 2011 20:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fogus/797389 to your computer and use it in GitHub Desktop.
Save fogus/797389 to your computer and use it in GitHub Desktop.
(defn iota [t nxt stop y]
(take-while stop (iterate #(t (nxt %)) y)))
(iota identity inc #(< % 10) 1)
(def upto (fn [end start]
(iota identity inc #(< % end) start)))
(def downto (fn [end start]
(iota identity dec #(> % end) start)))
(upto 10 1)
(downto 10 20)
(defn to [start end]
(if (<= start end)
(upto end start)
(downto end start)))
(to 10 20)
(to 20 10)
(to 5 -5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment