This commit is contained in:
SuperCraftAlex
2024-03-09 18:34:25 +01:00
parent a2f89fc962
commit 6f80ab30a3
31 changed files with 860 additions and 890 deletions

13
doc/lazy_seq.md Normal file
View File

@@ -0,0 +1,13 @@
# Lazy Sequences
When writing recursive functions like Fibonacci, it is often easier and faster to use
lazy sequences.
Example:
```kt
val fib = lazySequence(0 to 1) { i, f ->
f(i-1) + f(i-2)
}
println(fib[10])
```
Note: If we call f for any number below 0, it will call f(0) instead.