Skip to content

Add takeIf and takeUnless functions#3

Merged
injoonH merged 1 commit into
mainfrom
feat/take-if-unless
Jul 27, 2025
Merged

Add takeIf and takeUnless functions#3
injoonH merged 1 commit into
mainfrom
feat/take-if-unless

Conversation

@injoonH

@injoonH injoonH commented Jul 27, 2025

Copy link
Copy Markdown
Owner

Features

  • Add takeIf() and takeUnless() functions.

@injoonH injoonH requested a review from Copilot July 27, 2025 11:56
@injoonH injoonH self-assigned this Jul 27, 2025
@injoonH injoonH added the enhancement New feature or request label Jul 27, 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 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)

@injoonH injoonH merged commit 3c9c535 into main Jul 27, 2025
@injoonH injoonH deleted the feat/take-if-unless branch July 27, 2025 11:57
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