Add takeIf and takeUnless functions#3
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds two new utility functions takeIf() and takeUnless() to the standard library, which conditionally return a value or null based on predicate evaluation.
- Implements
takeIf()function that returns the value if predicate is true, otherwise null - Implements
takeUnless()function that returns the value if predicate is false, otherwise null - Adds comprehensive test coverage and documentation for both functions
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/stdlib/common/takeIf.ts | Implements the takeIf function with TypeScript generics |
| src/stdlib/common/takeIf.spec.ts | Provides unit tests for takeIf function behavior |
| src/stdlib/common/takeUnless.ts | Implements the takeUnless function with TypeScript generics |
| src/stdlib/common/takeUnless.spec.ts | Provides unit tests for takeUnless function behavior |
| src/stdlib/common/index.ts | Exports the new functions from the common module |
| docs/api/core/kotlin-stdlib/kotlin/take-if.md | Documents the takeIf function with examples |
| docs/api/core/kotlin-stdlib/kotlin/take-unless.md | Documents the takeUnless function with examples |
| docs/.vitepress/config.mts | Adds navigation links for the new function documentation |
Comments suppressed due to low confidence (2)
src/stdlib/common/takeIf.spec.ts:6
- Consider adding test cases for edge cases such as null/undefined values, falsy values (0, '', false), and complex objects to ensure the function handles all TypeScript types correctly.
const result = takeIf(42, (it) => it > 0)
src/stdlib/common/takeUnless.spec.ts:6
- Consider adding test cases for edge cases such as null/undefined values, falsy values (0, '', false), and complex objects to ensure the function handles all TypeScript types correctly.
const result = takeUnless(42, (it) => it < 0)
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
takeIf()andtakeUnless()functions.