Skip to content

Commit 97df32d

Browse files
committed
Merge pull request jbranchaud#4 from sdegutis/patch-1
Update mapping-with-an-index.md
2 parents d209553 + 7141fa0 commit 97df32d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

clojure/mapping-with-an-index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ can reach for `map-indexed`. The `map-indexed` function can be used like so:
99
> (map-indexed (fn [idx item] (str idx " - " item)) foods)
1010
("0 - pizza" "1 - hotdog" "2 - chicken alfredo")
1111
```
12+
13+
Alternatively, `map` can take multiple sequences, and each becomes a new argument to the mapping function. By giving an infinite sequential list of numbers starting at 0 as the first sequence, you can pretend they're indices, like so:
14+
15+
```clojure
16+
> (map (fn [idx item] (str idx " - " item)) (range) foods)
17+
("0 - pizza" "1 - hotdog" "2 - chicken alfredo")
18+
```

0 commit comments

Comments
 (0)