Skip to content

Conversation

@AshGreyG
Copy link
Owner

@AshGreyG AshGreyG commented Jul 10, 2025

πŸ“ Description

This PR introduces a new method of Array namespace:

  • Array.Unshift<Arr, E>

🌴 PR Type

  • ✨ Feature
  • πŸ› Bugfix
  • πŸš‘ Hotfix
  • πŸ’‘ Doc comment
  • πŸ§ͺ Test
  • πŸ“ Document
  • πŸ‹ Other (please describe)

πŸ”₯ Linked issues

πŸ‘Ύ Additional context

β›³ Change log

  • I have updated the changelog/next.md with my changes.

Summary by Sourcery

Introduce the Array.Unshift type helper to the Array namespace for prepending elements to tuple types, and register corresponding tests and changelog updates

New Features:

  • Add Array.Unshift<Arr, E> type to prepend an element to tuple types

Documentation:

  • Fix changelog date formatting and add an entry for Array.Unshift

Tests:

  • Add type-level tests for Array.Unshift in lib-Array.test.ts and update the lib-gen script for its test cases

@sourcery-ai
Copy link

sourcery-ai bot commented Jul 10, 2025

Reviewer's Guide

Implements a new Array.Unshift utility by prepending an element to a tuple via variadic tuple spread, complete with JSDoc, unit tests, script integration, and changelog entry.

Class diagram for the new Array.Unshift type

classDiagram
  class Array {
    <<namespace>>
  }
  class Unshift {
    <<type>>
    +<Arr extends unknown[], E extends unknown> [E, ...Arr]
  }
  Array <|.. Unshift : contains
Loading

File-Level Changes

Change Details Files
Implement Unshift type alias for Arrays
  • Add JSDoc comment describing Unshift semantics
  • Define Unshift<Arr, E> = [E, ...Arr] type
lib/Array/index.d.ts
Add unit tests for Unshift
  • Add Expect assertions covering empty and non-empty arrays
  • Test element prepending in various scenarios
test/lib-Array.test.ts
Integrate Unshift into test generation script
  • Insert Array.Unshift case into lib-gen.sh test_cases
test/script/lib-gen.sh
Record Unshift in changelog
  • Add Unshift entry under 2025-07-10 release section
changelog/next.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@AshGreyG AshGreyG added enhancement New feature or request feature Add new features to the project labels Jul 10, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @AshGreyG - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `test/lib-Array.test.ts:20` </location>
<code_context>
   Expect<Equal<Array.CreateArrayFromLength<0>, []>>,
   Expect<Equal<Array.CreateArrayFromLength<-1>, []>>,

+  // Array.Unshift
+  Expect<Equal<Array.Unshift<[1,2,3], 4>, [4,1,2,3]>>,
+  Expect<Equal<Array.Unshift<[], []>, [[]]>>,
+  Expect<Equal<Array.Unshift<[1], []>, [[],1]>>,
+  Expect<Equal<Array.Unshift<[], 1>, [1]>>,
+
   // Array.MultipleConcat
</code_context>

<issue_to_address>
Missing tests for edge cases with complex element types in Array.Unshift.

Please add tests for unshifting arrays, objects, and union types to verify Unshift handles complex element types correctly.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
  Expect<Equal<Array.Unshift<[1,2,3], 4>, [4,1,2,3]>>,
  Expect<Equal<Array.Unshift<[], []>, [[]]>>,
  Expect<Equal<Array.Unshift<[1], []>, [[],1]>>,
  Expect<Equal<Array.Unshift<[], 1>, [1]>>,
=======
  Expect<Equal<Array.Unshift<[1,2,3], 4>, [4,1,2,3]>>,
  Expect<Equal<Array.Unshift<[], []>, [[]]>>,
  Expect<Equal<Array.Unshift<[1], []>, [[],1]>>,
  Expect<Equal<Array.Unshift<[], 1>, [1]>>,

  // Array.Unshift edge cases with complex element types
  Expect<Equal<Array.Unshift<[{a: 1}, {b: 2}], {c: 3}>, [{c: 3}, {a: 1}, {b: 2}]>>,
  Expect<Equal<Array.Unshift<[[1, 2], [3, 4]], [5, 6]>, [[5, 6], [1, 2], [3, 4]]>>,
  Expect<Equal<Array.Unshift<[1 | 2, 3], 4 | 5>, [4 | 5, 1 | 2, 3]>>,
  Expect<Equal<Array.Unshift<[], {foo: string; bar: number}>, [{foo: string; bar: number}]>>,
  Expect<Equal<Array.Unshift<[{x: number}], {y: boolean}>, [{y: boolean}, {x: number}]>>,
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click πŸ‘ or πŸ‘Ž on each comment and I'll use the feedback to improve your reviews.

@AshGreyG AshGreyG merged commit 5709af4 into main Jul 10, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request feature Add new features to the project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants