Closeable in common stdlib

#1

Closeable and Closeable.use are a very standard pattern.
So, I am very curious as to why it has not been included in the common standard library.

Closing low-level resources is a common problem, especially in Kotlin/Native.
Some libraries, such as KotlinX/IO are providing their own Closeable / use, but I don’t want to depend on KotlinX/IO just for access to Closeable!

Therefore, I ended up duplicating Closeable / use in my own multiplatform libraries, which is by essence a very bad idea :frowning:.

I searched common Kotlin places (discuss, youtrack, github) and couldn’t find any mention of this.

Any reason why Closeable is NOT in the common standard library?

#2

I guess it just hasn’t been implemented yet. Kotlin native is still in experimental access and so are multiplatform projects. There are hundreds of useful classes and interfaces in java and extracting the essentials into common takes time.
Just create an youtrack-issue (https://youtrack.jetbrains.com/issues/KT) and it will probably be added in the future. And I guess if you want to speed it up also create a PR on github :wink:

#3

Here it is :wink: https://youtrack.jetbrains.com/issue/KT-31066