Skip to content

Commit

Permalink
#178 Sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
naufalprakoso committed Jul 2, 2020
1 parent 9c9613e commit 1f46312
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
[![alt text][InstagramIcon]][Instagram]
[![alt text][TelegramIcon]][Telegram]

### [#178 Sequence](/codes/Sequence.kt)
![alt text](/screenshots/Sequence.png)

### [#177 Transient Annotation](/codes/Transient.kt)
![alt text](/screenshots/Transient.png)

Expand Down
31 changes: 31 additions & 0 deletions codes/Sequence.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
fun main() {

}

val data = mutableListOf<Int>()

fun initData() {
data.clear()
System.gc()
for (i in 0..1_000_000) {
data.add(i)
}
}

// When you process a bigger collection with more than one processing step,
// it will take more time.
fun processCollectionWithoutSequence() {
data.filter { it % 2 == 0 }.forEach {

}
}

// Use Sequence for bigger collections with more than one processing.

// Sequence are more efficient and faster for collection processing
// with more than single processing step.
fun processCollectionWithSequence() {
data.asSequence().filter { it % 2 == 0 }.forEach {

}
}
Binary file added screenshots/Sequence.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1f46312

Please sign in to comment.