Skip to content

Conversation

@oscarArismendi
Copy link

Added a sample function for constructors in Library.kt.

These are just the basics, but I remember when I was learning Kotlin that having examples for everything would’ve made me spend more time in the official documentation.

Related issue: KT-20357

@oscarArismendi oscarArismendi changed the title KT-20357: Add sample usages for array constructor functions in standa… KT-20357: Add sample usages for array constructor functions Oct 14, 2025
@oscarArismendi
Copy link
Author

Hi, just checking if I need to do anything else to move this toward review
cc @derekxu16 @SmialyKot @Tapchicoma @ddolovov @woainikk @anton-bannykh

/**
* Returns an array containing the specified [Double] numbers.
*
* @sample samples.collections.Arrays.Constructors.doubleArrayOf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update corresponding actual declarations.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it in a74af86

Let me know if that's what you wanted

class Constructors {
@Sample
fun doubleArrayOf() {
val doubleArray = doubleArrayOf(1.0, 2.5, 3.14)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to showcase that these functions produce an empty array when invoked without any arguments. WDYT?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Samples for array functions have been added as requested(Ref a74af86). I renamed the sample methods with a 'Sample' suffix to prevent recursive self-calls, but let me know what you think

@fzhinkin fzhinkin added the Standard Library Sample Pull request with samples for stdlib API label Nov 24, 2025
* Returns an array containing the specified elements.
*/
public expect inline fun <reified T> arrayOf(vararg elements: T): Array<T>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also makes sense to add a similar sample for arrayOf ^

Copy link
Author

@oscarArismendi oscarArismendi Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done on b49f96e

@oscarArismendi oscarArismendi force-pushed the KT-20357-array-of-samples branch from bbe6420 to b49f96e Compare December 6, 2025 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Standard Library Sample Pull request with samples for stdlib API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants