ClojureBridge/curriculum

for is missing

Closed this issue · 3 comments

One of the concepts needed for the app is for. Daniel kindly wrote something up, but I don't know where it should go. It should go in data structures, but that section is very full. Also, I can't quite picture where it goes there. Thoughts @cndreisbach ?

I think it should go after Sequences. We can break the data structures section into two parts if that makes sense.

I totally remember already updating this, but, apparently I didn't. Stashing the content from @flyingmachine so it doesn't get lost:

The for function iterates over all the combinations of the sequences it's given and returns a sequence:

(for [x [1 2 3]
      y ["a" "b" "c"]]
  (str x y))
; => ("1a" "1b" "1c" "2a" "2b" "2c" "3a" "3b" "3c")

You can also specify what combinations are allowed with the :when keyword:

(for [x [1 2 3]
      y ["a" "b" "c"]
      :when (> x 2)]
  (str x y))
("3a" "3b" "3c")

(for [x [1 2 3]
      y ["a" "b" "c"]
      :when (and (> x 2) (not= y "a"))]
  (str x y))
; => ("3b" "3c")

Resolved.