# MutableIntervalList

Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/lazy/layout/IntervalList.kt+class:androidx.compose.foundation.lazy.layout.MutableIntervalList) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.2.0) Common/AllAndroid/JVM
- Cmn

  ```
  class MutableIntervalList<T : Any?> : IntervalList<T>
  ```

*** ** * ** ***

Mutable version of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList`. It allows you to add new intervals via `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList#addInterval(kotlin.Int,kotlin.Any)`.

Note: this class is a part of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayout.composable#LazyLayout(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.foundation.lazy.layout.LazyLayoutPrefetchState,androidx.compose.foundation.lazy.layout.LazyLayoutMeasurePolicy)` harness that allows for building custom lazy layouts. LazyLayout and all corresponding APIs are still under development and are subject to change.

## Summary

| ### Public constructors |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList#MutableIntervalList()()` | Cmn |

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList#addInterval(kotlin.Int,kotlin.Any)(size: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, value: T)` Adds a new interval into this list. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList#forEach(kotlin.Int,kotlin.Int,kotlin.Function1)( fromIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, toIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, block: (https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList.Interval<T>) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Allows to iterate through all the intervals starting from the one containing `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList#forEach(kotlin.Int,kotlin.Int,kotlin.Function1)` until the one containing `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList#forEach(kotlin.Int,kotlin.Int,kotlin.Function1)`. | Cmn |
| `open operator https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList.Interval<T>` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList#get(kotlin.Int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the interval containing the given `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList#get(kotlin.Int)`. | Cmn |

| ### Public properties |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList#size()` The total amount of items in all the intervals. | Cmn |

## Public constructors

### MutableIntervalList

Cmn

```
<T : Any?> MutableIntervalList()
```

## Public functions

### addInterval

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.2.0)

```
fun addInterval(size: Int, value: T): Unit
```

Adds a new interval into this list.

| Parameters |
|---|---|
| `size: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the amount of items in the new interval. |
| `value: T` | the value representing this interval. |

### forEach

Cmn

```
open fun forEach(
    fromIndex: Int = 0,
    toIndex: Int = size - 1,
    block: (IntervalList.Interval<T>) -> Unit
): Unit
```

Allows to iterate through all the intervals starting from the one containing `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList#forEach(kotlin.Int,kotlin.Int,kotlin.Function1)` until the one containing `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList#forEach(kotlin.Int,kotlin.Int,kotlin.Function1)`.

| Parameters |
|---|---|
| `fromIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | we will start iterating from the interval containing this index. |
| `toIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = size - 1` | the last interval we iterate through will contain this index. This index should be not smaller than `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList#forEach(kotlin.Int,kotlin.Int,kotlin.Function1)`. |
| `block: (https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList.Interval<T>) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | will be invoked on each interval within the defined indexes |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-index-out-of-bounds-exception/index.html` | if the indexes are not within 0..`https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList#size()` - 1 range. |

### get

Cmn

```
open operator fun get(index: Int): IntervalList.Interval<T>
```

Returns the interval containing the given `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList#get(kotlin.Int)`.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-index-out-of-bounds-exception/index.html` | if the index is not within 0..`https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList#size()` - 1 range. |

## Public properties

### size

Cmn

```
open val size: Int
```

The total amount of items in all the intervals.

Note that it is not the amount of intervals, but the sum of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList.Interval#size()` for all the intervals added into this list.