Skip to content

Conversation

@AshGreyG
Copy link
Owner

@AshGreyG AshGreyG commented Jul 9, 2025

πŸ“ Description

This PR adds two new methods in Array namespace:

  • Array.Reverse<Arr>
  • Array.Shift<Arr, Mode>

🌴 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 Array.Reverse and Array.Shift type utilities, refine existing array-type internals, and add Boolean.Not tests

New Features:

  • Add Array.Reverse<Arr> type to reverse tuple types
  • Add Array.Shift<Arr, Mode> type to extract shifted element or remaining tuple

Enhancements:

  • Standardize internal count accumulators to use unknown[] in array-type helpers

Documentation:

  • Update changelog with new array methods entries

Tests:

  • Add Boolean.Not test cases and update test script mapping for Boolean.Not

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

sourcery-ai bot commented Jul 9, 2025

Reviewer's Guide

Implements two new Array namespace utilitiesβ€”Reverse and Shiftβ€”via recursive conditional types, refactors helper type defaults, updates the changelog, and adjusts Boolean.Not tests.

Class diagram for new Array.Reverse and Array.Shift types

classDiagram
  class Array {
  }
  class Reverse {
    <<type>>
    +Reverse<Arr extends unknown[], Result extends unknown[] = []>
  }
  class Shift {
    <<type>>
    +Shift<Arr extends unknown[], Mode extends "get-rest"|"get-shift-element" = "get-rest">
  }
  Array <|.. Reverse : contains
  Array <|.. Shift : contains
Loading

File-Level Changes

Change Details Files
Refactor default type parameters in helper utilities
  • Changed default Count type in CreateArrayFromLength from T[] to unknown[]
  • Changed default Count type in At from unknown[] to 0[]
  • Updated recursive At call to accumulate placeholder zeros instead of elements
lib/Array/index.d.ts
Add Array.Reverse type method
  • Implemented recursive Reverse<Arr, Result> using tail recursion
  • Added JSDoc comments and usage examples for Reverse
lib/Array/index.d.ts
Add Array.Shift type method with two modes
  • Implemented Shift<Arr, Mode> to return either the rest or the shifted element
  • Added JSDoc comments and examples illustrating both modes
lib/Array/index.d.ts
Update changelog with new methods
  • Documented addition of Array.Reverse and Array.Shift in changelog/next.md
changelog/next.md
Adjust tests for Boolean.Not
  • Added Boolean.Not test cases in test/lib-Boolean.test.ts
  • Corrected test script entries in test/script/lib-gen.sh to reference Boolean.Not
test/lib-Boolean.test.ts
test/script/lib-gen.sh

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

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> `lib/Array/index.d.ts:361` </location>
<code_context>
 export type Push<Arr extends unknown[], E extends unknown> = [...Arr, E];

+/**
+ * This method is like `Array.prototype.revers`, it reverses the array.
+ * 
+ * @param Arr The array to be reversed.
</code_context>

<issue_to_address>
Typo in method description: 'revers' should be 'reverse'.

Please correct the typo in the description to 'reverse' to avoid confusion in the documentation.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
/**
 * This method is like `Array.prototype.revers`, it reverses the array.
 * 
 * @param Arr The array to be reversed.
 * @param Result The array to store the final reversed result in the process
 * procedure.
 * @returns The reversed array.
 * 
 * @example
 * type Reverse1 = Array.Reverse<[1, 2, 3]>;  // [3, 2, 1]
 * type Reverse2 = Array.Reverse<[]>;         // []
 */
=======
/**
 * This method is like `Array.prototype.reverse`, it reverses the array.
 * 
 * @param Arr The array to be reversed.
 * @param Result The array to store the final reversed result in the process
 * procedure.
 * @returns The reversed array.
 * 
 * @example
 * type Reverse1 = Array.Reverse<[1, 2, 3]>;  // [3, 2, 1]
 * type Reverse2 = Array.Reverse<[]>;         // []
 */
>>>>>>> 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.

Comment on lines 360 to 371
/**
* This method is like `Array.prototype.revers`, it reverses the array.
*
* @param Arr The array to be reversed.
* @param Result The array to store the final reversed result in the process
* procedure.
* @returns The reversed array.
*
* @example
* type Reverse1 = Array.Reverse<[1, 2, 3]>; // [3, 2, 1]
* type Reverse2 = Array.Reverse<[]>; // []
*/
Copy link

Choose a reason for hiding this comment

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

issue (typo): Typo in method description: 'revers' should be 'reverse'.

Please correct the typo in the description to 'reverse' to avoid confusion in the documentation.

Suggested change
/**
* This method is like `Array.prototype.revers`, it reverses the array.
*
* @param Arr The array to be reversed.
* @param Result The array to store the final reversed result in the process
* procedure.
* @returns The reversed array.
*
* @example
* type Reverse1 = Array.Reverse<[1, 2, 3]>; // [3, 2, 1]
* type Reverse2 = Array.Reverse<[]>; // []
*/
/**
* This method is like `Array.prototype.reverse`, it reverses the array.
*
* @param Arr The array to be reversed.
* @param Result The array to store the final reversed result in the process
* procedure.
* @returns The reversed array.
*
* @example
* type Reverse1 = Array.Reverse<[1, 2, 3]>; // [3, 2, 1]
* type Reverse2 = Array.Reverse<[]>; // []
*/

@AshGreyG AshGreyG merged commit e3c6a5d into main Jul 9, 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