# What is the use of Sequence\<T\>.asSequence()?

**URL:** <https://discuss.kotlinlang.org/t/what-is-the-use-of-sequence-t-assequence/13033>\
**Category:** Uncategorized\
**Created:** [June 10, 2019, 8:52pm UTC](https://discuss.kotlinlang.org/t/what-is-the-use-of-sequence-t-assequence/13033 "2019-06-10T20:52:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chipays](https://avatars.discourse-cdn.com/v4/letter/c/ad7895/32.png) [@chipays](https://discuss.kotlinlang.org/u/chipays)\
**Post date:** [June 10, 2019, 8:52pm UTC](https://discuss.kotlinlang.org/t/what-is-the-use-of-sequence-t-assequence/13033/1 "2019-06-10T20:52:51Z")

</div>

There’s an extension function in the [standard library](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/as-sequence.html#assequence) for `Sequence`, its implementation is as follows:

```nohighlight
/**
 * Returns this sequence as a [Sequence].
 */
@kotlin.internal.InlineOnly
public inline fun <T> Sequence<T>.asSequence(): Sequence<T> {
    return this
}

```

At first sight it doesn’t look like this function has any use at all, it returns the exact same object.

What was the reason for adding this function?

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [June 10, 2019, 9:47pm UTC](https://discuss.kotlinlang.org/t/what-is-the-use-of-sequence-t-assequence/13033/2 "2019-06-10T21:47:39Z")

</div>

It doesn’t hurt. Since it just returns the receiver and is inline only it will never effect the generated bytecode. The upside of this function is that it makes it easy to switch between iterables and sequences. AFAIK sequences and iterables have exactly the same functions so having this function makes sense from this standpoint.
