Skip to content

Add lambda expression and map() + filter() functions with ARM syntax#1238

Open
Gijsreyn wants to merge 25 commits intoPowerShell:mainfrom
Gijsreyn:gh-57/main/add-map-lambda-function
Open

Add lambda expression and map() + filter() functions with ARM syntax#1238
Gijsreyn wants to merge 25 commits intoPowerShell:mainfrom
Gijsreyn:gh-57/main/add-map-lambda-function

Conversation

@Gijsreyn
Copy link
Collaborator

@Gijsreyn Gijsreyn commented Nov 5, 2025

PR Summary

This PR implements lambda expressions and the map() function for DSC configuration documents, enabling array transformations. The implementation uses ARM compatible syntax e.g., (lambda('param', body) and lambdaVariables('param'))

Example usage:

# Transform array elements
map(createArray(1, 2, 3), lambda('x', mul(lambdaVariables('x'), 2)))
# Returns: [2, 4, 6]

Seperated tests in a different file.

PR Context

Partially addresses #57.

Copy link
Contributor

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 implements lambda expressions and the map() function for DSC configuration documents, using ARM-compatible syntax (lambda('param', body) and lambdaVariables('param')). The implementation stores lambdas in the context with unique UUID-based identifiers and evaluates them by binding lambda parameters to array elements.

Key changes:

  • Added Lambda struct and lambda-specific handling in the function evaluation pipeline
  • Implemented map(), lambda(), and lambdaVariables() functions for array transformations
  • Extended Context with lambda storage (lambdas) and lambda parameter bindings (lambda_variables)

Reviewed Changes

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

Show a summary per file
File Description
lib/dsc-lib/src/parser/functions.rs Added Lambda struct and FunctionArg::Lambda variant; special handling for lambda() function to bypass normal evaluation
lib/dsc-lib/src/functions/mod.rs Implemented invoke_lambda() to create and store lambda objects with UUID-based IDs; registered new lambda-related functions
lib/dsc-lib/src/functions/map.rs Implemented array transformation function that evaluates lambdas for each element with optional index parameter
lib/dsc-lib/src/functions/lambda_variables.rs Implemented parameter lookup function for accessing lambda-bound variables during evaluation
lib/dsc-lib/src/functions/lambda.rs Created lambda function stub that returns error if invoked directly (handled specially elsewhere)
lib/dsc-lib/src/configure/context.rs Added lambda_variables HashMap and lambdas RefCell for lambda storage and parameter binding
lib/dsc-lib/locales/en-us.toml Added localized error messages and descriptions for lambda-related functions
dsc/tests/dsc_lambda.tests.ps1 Added integration tests for map() with various lambda scenarios (multiplication, index usage, range, empty array)

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

@Gijsreyn Gijsreyn force-pushed the gh-57/main/add-map-lambda-function branch from 97cf256 to b180986 Compare November 14, 2025 01:15
@Gijsreyn Gijsreyn requested a review from SteveL-MSFT December 12, 2025 05:39
@Gijsreyn Gijsreyn requested a review from SteveL-MSFT December 16, 2025 02:12
@Gijsreyn Gijsreyn changed the title Add lambda expression and map() function with ARM syntax Add lambda expression and map() + filter() functions with ARM syntax Dec 17, 2025
@Gijsreyn Gijsreyn requested a review from SteveL-MSFT December 17, 2025 02:48
Copy link
Member

@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

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

LGTM

@SteveL-MSFT
Copy link
Member

@Gijsreyn can you resolve the merge conflict and accept my suggestion to order then alpha?

@SteveL-MSFT
Copy link
Member

@Gijsreyn can you accept my suggestion to alpha order the ArgKind and I can merge?

@Gijsreyn
Copy link
Collaborator Author

Gijsreyn commented Mar 4, 2026

@SteveL-MSFT - my bad. I thought I had already pushed it. It's good to go!

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.

3 participants