Skip to content

Commit 871b3e9

Browse files
Update about.md
1 parent c6588e7 commit 871b3e9

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

concepts/map/about.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Introduction
22

33
In its most basic form, the higher-order function `map` accepts two arguments: a function `f` and a collection `coll`.
4-
It applies `f` to each element of `coll`, returning a list of the results in the same order.
4+
5+
Given `f` and `coll`, `map` applies `f` to each element of `coll`, returning a list of the results in the same order.
56

67
```clojure
78
(map inc [1 2 3]) ; => (2 3 4)
89
```
910

10-
The previous example applies the function `inc`, which increases a number by one, to each element of the vector `[1 2 3]`, and returns the result as the list `(2 3 4)`, where each element is the result of applying `inc` to the corresponding element of [1 2 3].
11+
The previous example applies the function `inc` to each element of the vector and returns the result as the list `(2 3 4)`.
1112

1213
Let's see another example where we greet someone with the message "Welcome":
1314

@@ -22,15 +23,21 @@ Let's see another example where we greet someone with the message "Welcome":
2223
## Returning a lazy sequence
2324

2425
Previously we provided a simplified explanation of how `map` operates.
26+
2527
In reality, `map` does not return a list but a *lazy* sequence.
26-
Although an explanation of lazy sequences is beyond the scope of this introduction, it essentially means that the elements of the resulting sequence are not generated until they are actually needed.
28+
29+
This essentially means that the elements of the resulting sequence are not generated until they are actually needed.
30+
2731
In other words, the function `f` passed to `map` is not applied until the elements of the resulting sequence are requested, for example, by printing them or retrieving their values.
32+
2833
This is advantageous when `f` is computationally expensive and only some elements are actually needed.
2934

3035
## Multiple collections
3136

3237
`map` allows multiple collections to be passed as input.
38+
3339
If the number of collections passed is `n`, the function `f` will receive `n` arguments, one from each collection.
40+
3441
The result is a sequence where the i-th element is obtained by applying `f` to the `n` elements at position i from each collection.
3542

3643
```clojure

0 commit comments

Comments
 (0)