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

@fzhinkin fzhinkin added the Standard Library Sample Pull request with samples for stdlib API label Nov 24, 2025
val byteArray = arrayOf(1, 2, 3)
assertPrints(byteArray.contentToString(), "[1, 2, 3]")

val booleanArray = arrayOf(true, false, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

@oscarArismendi, could you please elaborate why it's necessary to showcase creation of an array for every boxed primitive type?

In some way, it could be misleading as it gives an impression that arrayOf(true, false, true) and booleanArrayOf(true, false, true) are equivalent, but they are not.

Perhaps, something like val strings = arrayOf("Hello", "world") would be enough.

But it might be worth also adding a sample like val numbers: Array<Number> = arrayOf(3.14, 42L, 0.123f)

Copy link
Author

Choose a reason for hiding this comment

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

@fzhinkin My thought process was that I wanted to show all the possibilities, but now that you mention it, I agree it’s misleading. I’ll keep only the emptyArray example from the arrayOf test and add the two examples you suggested

Copy link
Author

Choose a reason for hiding this comment

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

Done on ab436f7

@oscarArismendi oscarArismendi force-pushed the KT-20357-array-of-samples branch from b49f96e to ab436f7 Compare December 12, 2025 03:18
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