-
-
Save bostonaholic/797714 to your computer and use it in GitHub Desktop.
iota clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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