# Getting a Pair from Collections

**URL:** <https://discuss.kotlinlang.org/t/getting-a-pair-from-collections/5208>\
**Category:** Libraries\
**Created:** [November 1, 2017, 4:05am UTC](https://discuss.kotlinlang.org/t/getting-a-pair-from-collections/5208 "2017-11-01T04:05:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![niksw7](https://avatars.discourse-cdn.com/v4/letter/n/aca169/32.png) [@niksw7](https://discuss.kotlinlang.org/u/niksw7)\
**Post date:** [November 1, 2017, 4:05am UTC](https://discuss.kotlinlang.org/t/getting-a-pair-from-collections/5208/1 "2017-11-01T04:05:37Z")

</div>

Hi,  
I was just wondering would it be feasible to have Collectons extension that can convert given array to pair by applying some custom transformation.  
An example in can give is reading String (“1,2” )and then getting a Pair(1,2) out of it?  
I know i can write a custom function but was just wondering if many of us do it frequently, can we have an extension for this?  
It could look like this  
val list = readLine()!!.split(" ").collectAsPair(someTransformation)

---

<div class="post-metadata">

**Author:** ![youhansr](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/youhansr/32/4052_2.png) [@youhansr](https://discuss.kotlinlang.org/u/youhansr)\
**Post date:** [November 1, 2017, 6:02am UTC](https://discuss.kotlinlang.org/t/getting-a-pair-from-collections/5208/2 "2017-11-01T06:02:18Z")

</div>

This feature is present in Kotlin 1.2-M2. Your interested features are `chunked` and `pairwise`. You could see these APIs [here](https://github.com/Kotlin/KEEP/blob/master/proposals/stdlib/window-sliding.md#description).  
If you are using Kotlin 1.1.x versions, you could use a library like [kommon](https://github.com/andrewoma/kommon/tree/master/src/test/kotlin/com/github/andrewoma/kommon). Look at [this test method](https://github.com/andrewoma/kommon/blob/6685331ec28a475ad88473cf5bb8f39f9eafd147/src/test/kotlin/com/github/andrewoma/kommon/collection/CollectionExtensionsTest.kt#L36) of the library.

---

<div class="post-metadata">

**Author:** ![niksw7](https://avatars.discourse-cdn.com/v4/letter/n/aca169/32.png) [@niksw7](https://discuss.kotlinlang.org/u/niksw7)\
**Post date:** [November 1, 2017, 8:25am UTC](https://discuss.kotlinlang.org/t/getting-a-pair-from-collections/5208/3 "2017-11-01T08:25:12Z")

</div>

That’s great. Thanks

---

<div class="post-metadata">

**Author:** ![alanfo](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@alanfo](https://discuss.kotlinlang.org/u/alanfo)\
**Post date:** [November 1, 2017, 11:10am UTC](https://discuss.kotlinlang.org/t/getting-a-pair-from-collections/5208/4 "2017-11-01T11:10:41Z")

</div>

Incidentally, the pairwise() function has now be renamed to zipWithNext().

This makes it clear that each element is zipped with the next element in the collection which wasn’t particularly clear from the previous name.
