# Sequence.flatMap { iterable }?

**URL:** <https://discuss.kotlinlang.org/t/sequence-flatmap-iterable/14675>\
**Category:** Language Design\
**Created:** [October 15, 2019, 9:20pm UTC](https://discuss.kotlinlang.org/t/sequence-flatmap-iterable/14675 "2019-10-15T21:20:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xduke](https://avatars.discourse-cdn.com/v4/letter/x/3da27b/32.png) [@xduke](https://discuss.kotlinlang.org/u/xduke)\
**Post date:** [October 15, 2019, 9:20pm UTC](https://discuss.kotlinlang.org/t/sequence-flatmap-iterable/14675/1 "2019-10-15T21:20:10Z")

</div>

I think it would be nice to have a version of flatMap on Sequence that takes an Iterable.

For example the second `asSequence()` call feels superfluous and reminds me of Java’s .stream() / .collect() ceremony.

```auto
val mobileNumbers = contacts.asSequence()
    .flatMap { it.phoneNumbers.asSequence() }
    .filter { it.type == "mobile" }
    .map { it.number }

```

Here’s the full code with the collection based variant.

```
data class PhoneNumber(val type: String, val number: String)
data class Contact(val name: String, val phoneNumbers: List<PhoneNumber>)

val mobileNumbers = contacts
    .flatMap { it.phoneNumbers }
    .filter { it.type == "mobile" }
    .map { it.number }

```

---

<div class="post-metadata">

**Author:** ![xduke](https://avatars.discourse-cdn.com/v4/letter/x/3da27b/32.png) [@xduke](https://discuss.kotlinlang.org/u/xduke)\
**Post date:** [October 21, 2019, 11:24am UTC](https://discuss.kotlinlang.org/t/sequence-flatmap-iterable/14675/2 "2019-10-21T11:24:37Z")

</div>

This has gotten a few likes and no comments, so I created [https://youtrack.jetbrains.com/issue/KT-34506](https://youtrack.jetbrains.com/issue/KT-34506)

Some votes would be great!
