Skip to content

Add count() and clamp() functions#29

Merged
Sander-Toonen merged 2 commits intomasterfrom
copilot/add-count-and-clamp-functions
Jan 23, 2026
Merged

Add count() and clamp() functions#29
Sander-Toonen merged 2 commits intomasterfrom
copilot/add-count-and-clamp-functions

Conversation

Copy link

Copilot AI commented Jan 23, 2026

Adds two new built-in functions: count() for array length and clamp() for bounding values.

Changes

  • count(array) - Returns number of items in an array
  • clamp(value, min, max) - Constrains value to [min, max] range
  • Language service documentation for IntelliSense
  • Syntax docs updated

Usage

const parser = new Parser();

// count() - array length
parser.evaluate('count([1, 2, 3, 4, 5])');  // 5
parser.evaluate('count([])');               // 0

// clamp() - bound values
parser.evaluate('clamp(5, 0, 10)');   // 5 (within range)
parser.evaluate('clamp(-5, 0, 10)');  // 0 (below min)
parser.evaluate('clamp(15, 0, 10)');  // 10 (above max)

Both functions return undefined when passed undefined arguments, consistent with existing function behavior.

Original prompt

Create a count() function that returns the number of items in an array. Also creata a clamp(value, min, max) function that ensure that a value says within bounds. Update documentation and the language server.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
Copy link

@Sander-Toonen Sander-Toonen left a comment

Choose a reason for hiding this comment

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

Rearrange all functions in docs/syntax.md. Create sections for numeric functions, string functions, array functions and object functions.

Copilot AI changed the title [WIP] Add count and clamp functions with updated documentation Add count() and clamp() functions Jan 23, 2026
@Sander-Toonen Sander-Toonen marked this pull request as ready for review January 23, 2026 15:48
Copilot AI review requested due to automatic review settings January 23, 2026 15:48
Copilot AI requested a review from Sander-Toonen January 23, 2026 15:48
@Sander-Toonen Sander-Toonen merged commit 7b0ea94 into master Jan 23, 2026
3 of 4 checks passed
Copilot stopped work on behalf of Sander-Toonen due to an error January 23, 2026 15:48
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

This PR introduces two new built-in functions, count() for array length and clamp() for numeric range bounding, and wires them through the parser, docs, and language service. It also adds targeted test coverage to ensure behavior matches existing conventions, especially around undefined handling.

Changes:

  • Added count(array) function in the array operations module, with tests and documentation describing its behavior and undefined handling.
  • Added clamp(value, min, max) function in the math/advanced module, with tests covering ranges, edge values, decimals, and undefined arguments.
  • Updated parser wiring, language service IntelliSense documentation, and syntax documentation to expose and describe the new functions.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/functions/functions-array-string.ts Adds unit tests validating count() behavior on empty, single, multi-element, and undefined-containing arrays, plus undefined arguments.
test/functions/functions-advanced.ts Adds unit tests validating clamp() behavior for in-range, below-min, above-max, negative ranges, decimals, and undefined arguments.
src/parsing/parser.ts Wires count and clamp into the parser’s built-in function map and re-exports, making them available in expressions.
src/language-service/language-service.documentation.ts Extends built-in function documentation to describe count and clamp for language service/IntelliSense consumers.
src/functions/math/advanced.ts Implements clamp() with undefined-aware handling and min/max bounding.
src/functions/array/operations.ts Implements count() with undefined passthrough and runtime type checks consistent with other array helpers (e.g., sum).
docs/syntax.md Updates syntax reference to include clamp and count in the pre-defined functions table with descriptions matching their implementations.

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

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