Skip to content

Commit

Permalink
Merge pull request #88 from naufalprakoso/master
Browse files Browse the repository at this point in the history
Adding Sequence
  • Loading branch information
savepopulation authored Jan 2, 2021
2 parents ed1c963 + 4f57ac6 commit 3825671
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]

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

### [#180 Providing Build Config Fields on Multi-Dimensional Flavor Types](/codes/MultiDimensionalFlavorConfigFields.gradle)
![alt text](/screenshots/MultiDimensionalFlavorConfigFields.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 3825671

Please sign in to comment.