# Public review of the Standard Library APIs \[Closed\]

**URL:** <https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362>\
**Category:** Libraries\
**Created:** [December 17, 2015, 1:32pm UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362 "2015-12-17T13:32:41Z")\
**Posts on this page:** 14\
**Page:** 4

<div class="post-metadata">

**Author:** ![yole](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yole/32/1425_2.png) [@yole](https://discuss.kotlinlang.org/u/yole)\
**Post date:** [January 11, 2016, 2:17pm UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/65 "2016-01-11T14:17:02Z")

</div>

The changed behavior of split() is very much intentional. Using a regex to split has non-trivial performance costs and surprising behavior in cases when a symbol you want to split with has special semantics in a regexp and needs to be escaped. We have explicitly separated methods which take a simple String (and don’t do any fancy regexp matching) and which take a Regex (which could be pre-compiled and stored as a constant).

---

<div class="post-metadata">

**Author:** ![pniederw1](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@pniederw1](https://discuss.kotlinlang.org/u/pniederw1)\
**Post date:** [January 12, 2016, 9:39pm UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/66 "2016-01-12T21:39:08Z")

</div>

**Utils**

These would be nice to have:

`Throwable.rootCause()` (as in Guava)

`Throwable.stackTraceAsString()` (as in Guava)

---

<div class="post-metadata">

**Author:** ![mplatvoet](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mplatvoet/32/7121_2.png) [@mplatvoet](https://discuss.kotlinlang.org/u/mplatvoet)\
**Post date:** [January 12, 2016, 10:52pm UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/67 "2016-01-12T22:52:21Z")

</div>

As I happen to just have stated in the Slack channel: I’m a bit dual about ThreadLocal. The property delegate is easily created but any (required) cleanup is easily forgotten, thus adding something like `ThreadLocal` delegates to the stdlib also introduces the risk of being used while not fully understood, hence leading to potential memory leaks.

That cleaning up also means you need to have a reference to the delegate itself in order to call some `remove` function. Or allow nulls to null the value out but that won’t work with vals and defies the purpose of the type system.

---

<div class="post-metadata">

**Author:** ![dalewking](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/dalewking/32/1496_2.png) [@dalewking](https://discuss.kotlinlang.org/u/dalewking)\
**Post date:** [January 12, 2016, 11:20pm UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/68 "2016-01-12T23:20:20Z")

</div>

> [@pniederw1](#):
>
> > [@ilya.gorbunov](#):
> >
> > This change would be rather disruptive at this moment, does it provide the value that justifies it?
> 
> I believe the proposed order is more logical, and the current order will take people by surprise. I’ll leave it to you whether you consider this worth fixing at this point. All I can say is that I’d happily adapt my own code, and that IntelliJ would likely do this for me anyways.

I disagree strongly that it is more logical. Conceptually, an array or list is like a map in that there is some value you use to refer to the values in the collection and then there are the values in the collection. So the index is analogous to the key in a map. I expect it to be index, value just as when iterating over entries in a map I expect it to be key, value and not the reverse.

---

<div class="post-metadata">

**Author:** ![pniederw1](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@pniederw1](https://discuss.kotlinlang.org/u/pniederw1)\
**Post date:** [January 13, 2016, 3:33am UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/69 "2016-01-13T03:33:48Z")

</div>

> [@mplatvoet](#):
>
> As I happen to just have stated in the Slack channel: I’m a bit dual about ThreadLocal. […]

Good points. Probably better not added to stdlib (and removed from my wish list).

---

<div class="post-metadata">

**Author:** ![pniederw1](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@pniederw1](https://discuss.kotlinlang.org/u/pniederw1)\
**Post date:** [January 13, 2016, 3:37am UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/70 "2016-01-13T03:37:34Z")

</div>

Groovy and Scala have `withIndex` methods, which put the index last. Ceylon and Kotlin have `indexed` methods, which put the index first. Looking at it now, both approaches make sense.

---

<div class="post-metadata">

**Author:** ![pniederw1](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@pniederw1](https://discuss.kotlinlang.org/u/pniederw1)\
**Post date:** [January 14, 2016, 9:03pm UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/71 "2016-01-14T21:03:58Z")

</div>

Did anything come out of [this](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-until-jan-11-2016/1362/13), JetBrains? Most of all, I constantly find myself in need of a variant of `apply` whose function takes a parameter rather than being an extension function. I have my own `applyIt`, but such a fundamental primitive should be in stdlib.

---

<div class="post-metadata">

**Author:** ![Suseika](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/suseika/32/1706_2.png) [@Suseika](https://discuss.kotlinlang.org/u/Suseika)\
**Post date:** [January 15, 2016, 1:07pm UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/72 "2016-01-15T13:07:25Z")

</div>

`apply` can be used as more than an object initializer. I, for one, use it in unit tests to avoid giving test data trivial names. Compare:

```
val rectangle = Rectangle(1, 2, 3, 4)
assert(rectangle.contains(Point(1,2))

```

and

```
Rectangle(1,2,3,4)
    .apply { assert(contains(Point(1,2)) }

```

---

<div class="post-metadata">

**Author:** ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)\
**Post date:** [January 16, 2016, 6:11pm UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/73 "2016-01-16T18:11:30Z")

</div>

> [@pniederw1](#):
>
> Did anything come out of this, JetBrains? Most of all, I constantly find myself in need of a variant of apply whose function takes a parameter rather than being an extension function.

We are not renaming any of existing scope functions, but we may provide later such variant of apply. The name of that function is discussable. I’ve reopened issue [KT-6903](https://youtrack.jetbrains.com/issue/KT-6903) to track it.

---

<div class="post-metadata">

**Author:** ![pniederw1](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@pniederw1](https://discuss.kotlinlang.org/u/pniederw1)\
**Post date:** [January 17, 2016, 10:57am UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/74 "2016-01-17T10:57:48Z")

</div>

@ilya.gorbunov That’s great to hear. What about the duplication between `with` and `T.run`, which are completely equivalent, except that one is a function and the other an `Any?` extension method? I’d prefer to write `foo.with { ... }`, as this name, which is also used in other languages, resonates much more with me than `foo.run { ... }`.

---

<div class="post-metadata">

**Author:** ![vic\_lau](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/vic_lau/32/1746_2.png) [@vic\_lau](https://discuss.kotlinlang.org/u/vic_lau)\
**Post date:** [January 19, 2016, 4:13am UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/75 "2016-01-19T04:13:09Z")

</div>

I’ve no idea where to put this though it is now Jan 19.

The documentation of “return” is wrong, see:

[https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/src/generated/\_Ranges.kt#L1089](https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/src/generated/_Ranges.kt#L1089)

and also the produced doc:

> **[coerceAtMost - Kotlin Programming Language](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/coerce-at-most.html)**

Should be:

> @return this value if it’s **less** than or equal to the [maximumValue] or the [maximumValue] otherwise.

---

<div class="post-metadata">

**Author:** ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)\
**Post date:** [January 20, 2016, 5:38pm UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/76 "2016-01-20T17:38:51Z")

</div>

> [@pniederw1](#):
>
> So result.groups[3]!!.value == result.groupValues[2]? Sounds like asking for trouble to me (very similar looks/names, incompatible indices).

After some discussion, we have decided not to drop zeroth group from the `groupValues` list, so that the same index value would refer to the same group both in `groups` and in `groupValues`.

The downside of this decision is that the `groupValues` list becomes less convenient for [destructuring assignment](https://kotlinlang.org/docs/reference/multi-declarations.html#destructuring-declarations). An intended way to destructure no longer works:  
`val (group1, group2) = match.groupValues`, because the first value now is the match value itself and not the first group value.

In order to make destructuring assignment possible, we’re introducing another property `MatchResult.destructured`, which only provides `component1`, `component2` … `component10` methods to satisfy the destructuring convention. Thus the usage would be:  
`val (group1, group2) = match.destructured`

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [January 21, 2016, 6:46am UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/77 "2016-01-21T06:46:47Z")

</div>

Thanks everyone! Now this call is closed

---

<div class="post-metadata">

**Author:** ![Roman\_Belov](https://avatars.discourse-cdn.com/v4/letter/r/fbc32d/32.png) [@Roman\_Belov](https://discuss.kotlinlang.org/u/Roman_Belov)\
**Post date:** [February 15, 2016, 1:50pm UTC](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/78 "2016-02-15T13:50:39Z")

</div>

Closed on February 15, 2016, 1:50pm UTC



[Previous page](https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362.md?page=3)
