Skip to content

Instantly share code, notes, and snippets.

@thieux
Created January 10, 2017 21:36
Show Gist options
  • Select an option

  • Save thieux/82581cd7ad849b80805851701d49271e to your computer and use it in GitHub Desktop.

Select an option

Save thieux/82581cd7ad849b80805851701d49271e to your computer and use it in GitHub Desktop.
Build incrementally a clojure function using the REPL
clojure-drafts.core> (repeat 2 :x)
(:x :x)
clojure-drafts.core> (map (fn [e] (repeat 2 e)) [:x])
((:x :x))
clojure-drafts.core> (map (fn [e] (repeat 3 e)) [:x])
((:x :x :x))
clojure-drafts.core> (map (fn [e] (repeat 3 e)) [:x :y])
((:x :x :x) (:y :y :y))
clojure-drafts.core> (flatten (map (fn [e] (repeat 3 e)) [:x :y]))
(:x :x :x :y :y :y)
clojure-drafts.core> (defn replicate-seq [times sequence] (flatten (map (fn [e] (repeat times e)) sequence)))
#'clojure-drafts.core/replicate-seq
clojure-drafts.core> (replicate-seq 3 [:x :y :z])
(:x :x :x :y :y :y :z :z :z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment