Skip to content

Instantly share code, notes, and snippets.

@bostonaholic
Forked from fogus/iota.clj
Created January 26, 2011 23:10
Show Gist options
  • Save bostonaholic/797714 to your computer and use it in GitHub Desktop.
Save bostonaholic/797714 to your computer and use it in GitHub Desktop.
iota clojure
(defn iota [t nxt stop y]
(take-while stop (iterate #(t (nxt %)) y)))
(def upto
(fn [start end]
(iota identity inc #(< % end) start)))
(def downto
(fn [start end]
(iota identity dec #(> % end) start)))
(upto 1 10)
(downto 20 10)
(defn to
([end]
(to 1 end))
([start end]
(if (<= start end)
(upto start end)
(downto start end))))
(to 10 20)
(to 20 10)
(to 5 -5)
(to 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment