Add first function series#10
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds four utility functions for retrieving the first element from arrays, following Kotlin's standard library API patterns. The functions provide different strategies for handling empty arrays and null values.
- Adds
first(),firstOrNull(),firstNotNullOf(), andfirstNotNullOfOrNull()functions to the collections module - Implements comprehensive test coverage for all new functions
- Includes complete documentation for each function with usage examples
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/stdlib/collections/index.ts | Exports the new first function series |
| src/stdlib/collections/first.ts | Implements first() function that throws on empty arrays |
| src/stdlib/collections/firstOrNull.ts | Implements firstOrNull() function that returns null for empty arrays |
| src/stdlib/collections/firstNotNullOf.ts | Implements firstNotNullOf() function with transform that throws if no non-null result |
| src/stdlib/collections/firstNotNullOfOrNull.ts | Implements firstNotNullOfOrNull() function with transform that returns null if no non-null result |
| src/stdlib/collections/*.spec.ts | Test files providing comprehensive coverage for all new functions |
| docs/api/core/kotlin-stdlib/kotlin.collections/*.md | Documentation files with function signatures and usage examples |
| docs/.vitepress/config.mts | Updates navigation to include the new function documentation |
Comments suppressed due to low confidence (2)
src/stdlib/collections/firstNotNullOf.spec.ts:7
- The test only covers the case where the transform function returns a non-null value for null input. Consider adding a test case where the transform function returns a non-null value for a non-null input element to ensure the function works correctly in all scenarios.
const result = firstNotNullOf(input, (it) => (it === null ? 42 : null))
src/stdlib/collections/firstNotNullOfOrNull.spec.ts:7
- The test cases only use identity transform functions. Consider adding a test with a more complex transform function to verify the function works correctly when the transform actually modifies the input values.
const result = firstNotNullOfOrNull(array, (it) => it)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Features
first(),firstNotNullOf(),firstNotNullOfOrNull(), andfirstOrNull()functions.