Skip to content

[WIP] Add array utility functions for expression evaluator#34

Merged
Sander-Toonen merged 3 commits intomasterfrom
copilot/add-array-utility-functions
Jan 23, 2026
Merged

[WIP] Add array utility functions for expression evaluator#34
Sander-Toonen merged 3 commits intomasterfrom
copilot/add-array-utility-functions

Conversation

Copy link

Copilot AI commented Jan 23, 2026

Plan: Add Array Utility and Type Checking Functions ✅

Array Functions

  • Add reduce as an alias for fold in array operations
  • Implement find(arr, predicate) function
  • Implement some(arr, predicate) function
  • Implement every(arr, predicate) function
  • Implement unique(arr) / distinct(arr) functions

Type Checking Functions

  • Implement isArray(value) function
  • Implement isObject(value) function
  • Implement isNumber(value) function
  • Implement isString(value) function
  • Implement isBoolean(value) function
  • Implement isNull(value) function
  • Implement isUndefined(value) function
  • Implement isFunction(value) function

Integration

  • Register all new functions in parser
  • Add language service documentation for all new functions
  • Add comprehensive tests for array functions
  • Add comprehensive tests for type checking functions
  • Update syntax documentation with function descriptions and examples

Validation

  • Run linter to check code style
  • Build the project
  • Run all tests to ensure nothing breaks
  • Manual validation of new functions
  • Code review (no issues found)
  • Security check (no vulnerabilities found)
Original prompt

Overview

Add several new array utility functions and type checking functions to the expression evaluator.

New Functions to Implement

Array Functions

  1. reduce as an alias for fold

    • Add reduce(arr, fn, initial) that works identically to the existing fold function
    • This provides a more familiar name for users coming from JavaScript
  2. find(arr, predicate)

    • Returns the first element in the array that satisfies the predicate function
    • Returns undefined or null if no element is found
    • Unlike indexOf, this returns the actual element, not the index
  3. some(arr, predicate)

    • Returns true if at least one element in the array satisfies the predicate
    • Returns false otherwise (including for empty arrays)
  4. every(arr, predicate)

    • Returns true if all elements in the array satisfy the predicate
    • Returns true for empty arrays (vacuous truth)
  5. unique(arr) / distinct(arr)

    • Returns a new array with duplicate values removed
    • Both unique and distinct should work as aliases for the same function

Type Checking Functions

Add the following type checking functions that return boolean values:

  • isArray(value) - Returns true if value is an array
  • isObject(value) - Returns true if value is an object (and not null/array)
  • isNumber(value) - Returns true if value is a number
  • isString(value) - Returns true if value is a string
  • isBoolean(value) - Returns true if value is a boolean
  • isNull(value) - Returns true if value is null
  • isUndefined(value) - Returns true if value is undefined
  • isFunction(value) - Returns true if value is a function (if applicable)

Requirements

  1. Implementation: Add all the functions listed above to the expression evaluator
  2. Documentation: Update the documentation to include all new functions with:
    • Function signatures
    • Description of behavior
    • Example usage
  3. Language Server: Update the language server to support the new functions with:
    • Autocompletion support
    • Function signatures/hints
    • Any relevant hover documentation
  4. Tests: Add comprehensive tests for all new functions covering:
    • Normal usage
    • Edge cases (empty arrays, no matches, etc.)
    • Type checking with various input types

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 23, 2026 18:39
Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
@Sander-Toonen Sander-Toonen marked this pull request as ready for review January 23, 2026 18:42
Copilot AI review requested due to automatic review settings January 23, 2026 18:42
@Sander-Toonen Sander-Toonen merged commit 9d46225 into master Jan 23, 2026
8 checks passed
Copilot AI requested a review from Sander-Toonen January 23, 2026 18:44
Copilot stopped work on behalf of Sander-Toonen due to an error January 23, 2026 18:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds new array utilities and type-checking helpers to the expression evaluator, including parser registration, language-service docs, and tests.

Changes:

  • Added array functions: reduce (alias of fold), find, some, every, unique, distinct.
  • Added type-checking functions: isArray, isObject, isNumber, isString, isBoolean, isNull, isUndefined, isFunction.
  • Registered new built-ins in the parser, updated language-service documentation, updated syntax docs, and added tests.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/functions/functions-type-checking.ts Adds test coverage for all new type-checking functions and some integration usage.
test/functions/functions-new-array.ts Adds test coverage for new array utility functions and aliases.
src/parsing/parser.ts Registers new functions in the default parser built-in function table.
src/language-service/language-service.documentation.ts Adds hover/signature documentation for new built-in functions.
src/functions/utility/type-checking.ts Implements the new type-checking utility functions.
src/functions/utility/index.ts Exports the new type-checking utilities from the utility module.
src/functions/array/operations.ts Implements new array operations and aliases (reduce, find, some, every, unique, distinct).
docs/syntax.md Documents the new functions and adds usage examples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 187 to +193
fold: fold,
reduce: reduce,
find: find,
some: some,
every: every,
unique: unique,
distinct: distinct,
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

The PR description/original plan specifies signatures like reduce(arr, fn, initial) and find(arr, predicate), but the implementation registers these as reduce(f, init, a) and find(f, a) (function first), consistent with existing map/filter/fold. Please update the PR description (or any externally visible docs) to match the implemented argument order to avoid confusion for reviewers/users.

Copilot uses AI. Check for mistakes.
| isString(v) | Returns `true` if `v` is a string, `false` otherwise. |
| isBoolean(v) | Returns `true` if `v` is a boolean, `false` otherwise. |
| isNull(v) | Returns `true` if `v` is null, `false` otherwise. |
| isUndefined(v)| Returns `true` if `v` is undefined, `false` otherwise. |
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

Markdown table row for isUndefined is missing a space before the column separator (| isUndefined(v)| ...), which makes the table formatting inconsistent with the surrounding rows. Consider aligning it with the other entries (| isUndefined(v) | ...).

Suggested change
| isUndefined(v)| Returns `true` if `v` is undefined, `false` otherwise. |
| isUndefined(v) | Returns `true` if `v` is undefined, `false` otherwise. |

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants