Skip to content

Conversation

@leonmk-aws
Copy link
Contributor

Reason for this change

The previously generated code for getting the values of the IxxRef in arrays was not readable, as a for loop to mutate the array in place and comma syntax were used to return the mutated array in a single line.
Before:

cdk.withResolved(props.${name}, (props.xx?.forEach((item: T | string, i: number, arr: Array<T | string>) => { arr[i] = (item as T)?.xxxRef?.xx ?? cdk.ensureStringOrUndefined(item, "xxx", "lambda.T | string"); }), props.xxx as Array<string>));

After:

cdk.mapArrayInPlace(props.layers, (item: IxxxRef | string) => (item as IxxxRef)?.xxxRef?.xxxArn ?? cdk.ensureStringOrUndefined(item, "xxx", "lambda.IxxxRef | string"))

Description of changes

Added a handwritten function to do the in place in mapping in a generic way, preserving type safety.

Description of how you validated changes

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@leonmk-aws leonmk-aws requested a review from a team as a code owner December 1, 2025 12:02
@github-actions github-actions bot added the p2 label Dec 1, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team December 1, 2025 12:02
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Dec 1, 2025
Comment on lines +131 to +136
if (arrayType) {
const lambdaScope: CallableDeclaration = { parameters: [], returnType: Type.VOID, name: 'LambdaScope' };
const mapper = new Lambda(
[new Parameter(lambdaScope, { name: 'item', type: arrayType })],
expr.ident(functionName).call(expr.ident('item')),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Oof. This could do with a helper couldn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution/core This is a PR that came from AWS. p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants