Skip to content

Add first function series#10

Merged
injoonH merged 2 commits into
mainfrom
feat/first
Aug 6, 2025
Merged

Add first function series#10
injoonH merged 2 commits into
mainfrom
feat/first

Conversation

@injoonH

@injoonH injoonH commented Aug 6, 2025

Copy link
Copy Markdown
Owner

Features

  • Add first(), firstNotNullOf(), firstNotNullOfOrNull(), and firstOrNull() functions.

@injoonH injoonH requested a review from Copilot August 6, 2025 00:34
@injoonH injoonH self-assigned this Aug 6, 2025
@injoonH injoonH added the enhancement New feature or request label Aug 6, 2025

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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(), and firstNotNullOfOrNull() 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)

@injoonH injoonH merged commit a9cbbff into main Aug 6, 2025
@injoonH injoonH deleted the feat/first branch August 6, 2025 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants