Skip to content

Commit f742bc8

Browse files
Vixb1122elizarov
authored andcommitted
Update coroutines-guide-ui.md
perform correct naive computation of Fibonacci numbers
1 parent 6640b2b commit f742bc8

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

ui/coroutines-guide-ui.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ perform naive computation of [Fibonacci numbers](https://en.wikipedia.org/wiki/F
440440

441441
```kotlin
442442
fun fib(x: Int): Int =
443-
if (x <= 1) 1 else fib(x - 1) + fib(x - 2)
443+
if (x <= 1) x else fib(x - 1) + fib(x - 2)
444444
```
445445

446446
We'll be computing larger and larger Fibonacci number each time the circle is clicked.
@@ -505,7 +505,7 @@ fun setup(hello: Text, fab: Circle) {
505505

506506
```kotlin
507507
suspend fun fib(x: Int): Int = withContext(CommonPool) {
508-
if (x <= 1) 1 else fib(x - 1) + fib(x - 2)
508+
if (x <= 1) x else fib(x - 1) + fib(x - 2)
509509
}
510510
```
511511

@@ -528,7 +528,7 @@ suspend fun fib(x: Int): Int = withContext(CommonPool) {
528528
}
529529

530530
fun fibBlocking(x: Int): Int =
531-
if (x <= 1) 1 else fibBlocking(x - 1) + fibBlocking(x - 2)
531+
if (x <= 1) x else fibBlocking(x - 1) + fibBlocking(x - 2)
532532
```
533533

534534
> You can get full code [here](kotlinx-coroutines-javafx/src/test/kotlin/guide/example-ui-blocking-03.kt).

ui/kotlinx-coroutines-javafx/src/test/kotlin/guide/example-ui-blocking-01.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fun Node.onClick(action: suspend (MouseEvent) -> Unit) {
7272
}
7373

7474
fun fib(x: Int): Int =
75-
if (x <= 1) 1 else fib(x - 1) + fib(x - 2)
75+
if (x <= 1) x else fib(x - 1) + fib(x - 2)
7676

7777
fun setup(hello: Text, fab: Circle) {
7878
var result = "none" // the last result

ui/kotlinx-coroutines-javafx/src/test/kotlin/guide/example-ui-blocking-02.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,5 @@ fun setup(hello: Text, fab: Circle) {
9090
}
9191

9292
suspend fun fib(x: Int): Int = withContext(CommonPool) {
93-
if (x <= 1) 1 else fib(x - 1) + fib(x - 2)
93+
if (x <= 1) x else fib(x - 1) + fib(x - 2)
9494
}

ui/kotlinx-coroutines-javafx/src/test/kotlin/guide/example-ui-blocking-03.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ suspend fun fib(x: Int): Int = withContext(CommonPool) {
9494
}
9595

9696
fun fibBlocking(x: Int): Int =
97-
if (x <= 1) 1 else fibBlocking(x - 1) + fibBlocking(x - 2)
97+
if (x <= 1) x else fibBlocking(x - 1) + fibBlocking(x - 2)

0 commit comments

Comments
 (0)