Skip to content

Instantly share code, notes, and snippets.

@gbarrancos
Created April 24, 2011 15:17
Show Gist options
  • Save gbarrancos/939616 to your computer and use it in GitHub Desktop.
Save gbarrancos/939616 to your computer and use it in GitHub Desktop.
Loop + Maping with a side effecty fn over a seq
(defn side-effecty-fn [arg]
(print (str "Hit the fn: " arg "\n" ))
)
(defn loopy [begin end]
(loop [current begin]
(if (> current end)
"Done"
(do
(print (str "Calling with " current "\n"))
(dorun (map side-effecty-fn (cons current ["aaa" "bbb"])))
(recur (inc current))))))
@gbarrancos
Copy link
Author

Expected: (loopy 2 3)
Calling with 2
Hit the fn: 2
Hit the fn: aaa
Hit the fn: bbb
Calling with 3
Hit the fn: 3
Hit the fn: aaa
Hit the fn: bbb
"Done"

Actual:
Calling with 2
Calling with 3
"Done"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment