---
description: 조건식을 만족하는 값들의 리스트를 반환
---

# takeWhile

```kotlin
public inline fun <T> Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<T> {
    val list = ArrayList<T>()
    for (item in this) {
        if (!predicate(item))
            break 
        list.add(item)
    }
    return list
}


val list = listOf(1, 2, 3, 4, 5)
println(list.takeWhile{ it < 3 })  // [1, 2]
```
