clean up
This commit is contained in:
26
doc/batched_sequences.md
Normal file
26
doc/batched_sequences.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Batched sequences
|
||||
## Source
|
||||
You should make all your sources return `BatchSequence<T>`
|
||||
and then you can use the `.batched(count: Int)` function
|
||||
to drastically decrease the amount of single reads in the original source.
|
||||
|
||||
Example:
|
||||
```kt
|
||||
File("text.txt") // File
|
||||
.openRead() // BatchSequence<Byte>
|
||||
.batched(64) // BatchSequence<Byte>
|
||||
```
|
||||
|
||||
## Sink
|
||||
You should make all your sinks take `BatchSequence<T>`
|
||||
and then you can use the `.asBatch()` function to allow
|
||||
the sink to get multiple bytes at once.
|
||||
|
||||
Example:
|
||||
```kt
|
||||
val data = myData // Sequence<Byte>
|
||||
.asBatch() // BatchSequence<Byte>
|
||||
|
||||
File("text.txt")
|
||||
.write(data)
|
||||
```
|
13
doc/lazy_seq.md
Normal file
13
doc/lazy_seq.md
Normal 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.
|
Reference in New Issue
Block a user