Skip to content

Commit 1fa5dec

Browse files
committed
what-is-fp: adjust code
1 parent fb80a9c commit 1fa5dec

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/pages/intro/what-is-fp.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ In my view functional programming is not about immutability, or keeping to "the
3030
```scala mdoc:silent
3131
def sum(numbers: List[Int]): Int = {
3232
var total = 0
33-
numbers.foreach(x => total = total + x)
33+
numbers foreach { x => total = total + x }
3434
total
3535
}
3636
```
@@ -50,7 +50,7 @@ val it2 = Iterator(1, 2, 3, 4)
5050
```
5151

5252
```scala mdoc
53-
it.zip(it2).next()
53+
(it zip it2).next()
5454
```
5555

5656
However if we pass the same generator twice we get a surprising result.
@@ -60,7 +60,7 @@ val it3 = Iterator(1, 2, 3, 4)
6060
```
6161

6262
```scala mdoc
63-
it3.zip(it3).next()
63+
(it3 zip it3).next()
6464
```
6565

6666
The usual functional programming solution is to avoid mutable state but we can envisage other possibilities. For example, an [effect tracking system][effect-system] would allow us to avoid combining two generators that use the same memory region. These systems are still research projects, however.

0 commit comments

Comments
 (0)