Kotlin List reduce(), reduceIndexed(), reduceRight(), reduceRightIndexed() methods example

kotlin-list-reduce-reduceindexed-reduceright-reducerightindexed-methods-example-feature-image

In the tutorial, Grokonez will show you how to work with Kotlin List methods reduce(), reduceIndexed(), reduceRight(), reduceRightIndexed().

I. Kotlin List reduce methods

1. reduce()

reduce() accumulates value starting with the first element and applying [operation] from left to right to current accumulator value and each element.

Method signature:

Practice:

2. reduceIndexed()

reduceIndexed() accumulates value starting with the first element and applying [operation] from left to right to current accumulator value and each element with its index in the given collection.

Method signature:

Practice:

3. reduceRight()

reduceRight() opposites with reduce(). It accumulates value starting with last element and applying [operation] from right to left to each element and current accumulator value.

Method signature:

Practice:

4. reduceRightIndexed()

reduceRightIndexed() opposites with reduceIndexed(). Its accumulates value starting with last element and applying [operation] from right to left to each element with its index in the given list and current accumulator value.

Method signature:

Practice:

II. Full Sourcecode



By grokonez | January 17, 2018.

Last updated on September 6, 2018.



Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*