# IntervalList

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.IntervalList) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.2.0) Common/AllAndroid/JVM
- Cmn

  ```
  sealed interface IntervalList<T : Any?>
  ```
Known direct subclasses [MutableIntervalList](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList` | Mutable version of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList`. |

*** ** * ** ***

The list consisting of multiple intervals.

It is useful when you want to define your own dsl similar to the one used by LazyColumn where list items can be defined via multiple item/items calls.

This interface is read only, in order to create a list you need to use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/MutableIntervalList`.

| Parameters |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?>` | type of values each interval contains in `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList.Interval#value()`. 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

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList.Interval<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?>` The interval holder. |

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList#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 )` Iterates through all the intervals starting from the one containing `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList#forEach(kotlin.Int,kotlin.Int,kotlin.Function1)` until the one containing `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList#forEach(kotlin.Int,kotlin.Int,kotlin.Function1)`. | Cmn |
| `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/IntervalList#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 |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList#size()` The total amount of items in all the intervals. | Cmn |

## Public functions

### forEach

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

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

Iterates through all the intervals starting from the one containing `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList#forEach(kotlin.Int,kotlin.Int,kotlin.Function1)` until the one containing `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/IntervalList#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/IntervalList#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/IntervalList#size()` - 1 range. |

### get

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

```
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 Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.2.0)

```
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.