-
Notifications
You must be signed in to change notification settings - Fork 56
Add shallowMerge function
#1274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add shallowMerge function
#1274
Conversation
|
|
||
| The `shallowMerge()` function takes an array of objects and combines them into a single | ||
| object by merging their properties. When the same property name appears in multiple objects, | ||
| the value from the last object in the array takes precedence. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| the value from the last object in the array takes precedence. | |
| the value from the last object in the array with that property takes precedence. |
| object by merging their properties. When the same property name appears in multiple objects, | ||
| the value from the last object in the array takes precedence. | ||
|
|
||
| This is a **shallow merge**, meaning: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| This is a **shallow merge**, meaning: | |
| This is a _shallow merge_, which applies the following rules: |
| - Top-level properties are merged from all objects | ||
| - If a property value is an object, it replaces the entire object from previous objects | ||
| rather than merging the nested properties | ||
| - Arrays and other complex types are also replaced entirely, not combined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - Top-level properties are merged from all objects | |
| - If a property value is an object, it replaces the entire object from previous objects | |
| rather than merging the nested properties | |
| - Arrays and other complex types are also replaced entirely, not combined | |
| - The first object in the array defines the base value for the merged object. | |
| - The function processes each object in the array in the order they're defined. | |
| - When processing each object, the function iterates over every top-level property defined for that | |
| object and: | |
| - If the merged object doesn't already have the property, the function adds that property to the | |
| merged object with the value from the current object. | |
| - If the merged object does have the property, the function _replaces_ the existing value with | |
| the value from the current object, even when the value is an object or array. |
| - Building composite configuration objects from multiple sources | ||
| - Applying configuration overrides where later values take precedence | ||
| - Combining default settings with user-specified customizations | ||
| - Merging environment-specific configurations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - Building composite configuration objects from multiple sources | |
| - Applying configuration overrides where later values take precedence | |
| - Combining default settings with user-specified customizations | |
| - Merging environment-specific configurations | |
| - Building composite configuration objects from multiple sources. | |
| - Applying configuration overrides where later values take precedence. | |
| - Combining default settings with user-specified customizations. | |
| - Merging environment-specific configurations. |
| The shallow merge behavior differs from a deep merge (like [`union()`][00]) where nested | ||
| objects would be recursively merged. With `shallowMerge()`, nested structures are replaced | ||
| entirely by the last object's value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The shallow merge behavior differs from a deep merge (like [`union()`][00]) where nested | |
| objects would be recursively merged. With `shallowMerge()`, nested structures are replaced | |
| entirely by the last object's value. | |
| The shallow merge behavior differs from a deep merge (like [`union()`][00]) where nested | |
| objects are recursively merged. The `shallowMerge()` function replaces nested structures | |
| entirely with the value defined by the last object with that property in the input array. |
| This tries `python3` first, falls back to `python`, and finally uses a default path if | ||
| neither is found in PATH. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| This tries `python3` first, falls back to `python`, and finally uses a default path if | |
| neither is found in PATH. | |
| In this example, the function first looks for `python3` in the `PATH` environmental variable. If | |
| that executable isn't discovered, it then looks for `python`. If neither executable is discovered, | |
| it falls back to the specified default value, `/usr/bin/python3`. |
| docker: "[tryWhich('docker')]" | ||
| kubectl: "[tryWhich('kubectl')]" | ||
| helm: "[tryWhich('helm')]" | ||
| allFound: "[and(not(equals(tryWhich('docker'), null())), not(equals(tryWhich('kubectl'), null())), not(equals(tryWhich('helm'), null())))]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| allFound: "[and(not(equals(tryWhich('docker'), null())), not(equals(tryWhich('kubectl'), null())), not(equals(tryWhich('helm'), null())))]" | |
| allFound: >- | |
| [and( | |
| not(equals(tryWhich('docker'), null())), | |
| not(equals(tryWhich('kubectl'), null())), | |
| not(equals(tryWhich('helm'), null())) | |
| )] |
| The name of the executable to locate. On Windows, the function automatically checks for | ||
| common executable extensions (.exe, .cmd, .bat, .ps1, etc.) if no extension is provided. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The name of the executable to locate. On Windows, the function automatically checks for | |
| common executable extensions (.exe, .cmd, .bat, .ps1, etc.) if no extension is provided. | |
| The name of the executable to locate. On Windows, it automatically checks for common executable | |
| extensions, like `.exe, `.cmd`, and `.bat`, if no extension is provided. |
| The function returns `null` instead of generating errors when the executable is not found. | ||
| It will return an error only if: | ||
|
|
||
| - **Not a string**: The input is not a string (e.g., number, array, object, null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The function returns `null` instead of generating errors when the executable is not found. | |
| It will return an error only if: | |
| - **Not a string**: The input is not a string (e.g., number, array, object, null) | |
| The function returns `null` instead of generating errors when the executable isn't found. | |
| The function only returns an error when the input isn't a string. |
| - The function searches the PATH environment variable in the same order as the operating system | ||
| - On Windows, common executable extensions are automatically checked (.exe, .cmd, .bat, .ps1, etc.) | ||
| - Returns `null` (not an error) when the executable is not found | ||
| - The returned path is always absolute | ||
| - Use with [`if()`][00] or [`coalesce()`][01] for conditional logic based on tool availability | ||
| - The search is case-insensitive on Windows and case-sensitive on Unix-like systems | ||
| - Symbolic links are resolved to their target paths |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - The function searches the PATH environment variable in the same order as the operating system | |
| - On Windows, common executable extensions are automatically checked (.exe, .cmd, .bat, .ps1, etc.) | |
| - Returns `null` (not an error) when the executable is not found | |
| - The returned path is always absolute | |
| - Use with [`if()`][00] or [`coalesce()`][01] for conditional logic based on tool availability | |
| - The search is case-insensitive on Windows and case-sensitive on Unix-like systems | |
| - Symbolic links are resolved to their target paths | |
| - The function searches the `PATH` environment variable in the same order as the operating system. | |
| - On Windows, the function automatically checks for the executable with common extensions, like | |
| `.exe`, `.cmd`, and `.bat`, when the input string doesn't define an extension. For example, if | |
| the input is `dsc`, the function would return `dsc.exe` if available in `PATH`. | |
| - The function returns `null` when the executable isn't found instead of raising an error. | |
| - The function always returns the absolute path to a discovered executable. | |
| - Use with [`if()`][00] or [`coalesce()`][01] for conditional logic based on tool availability. | |
| - The function searches for the executable case-insensitively on Windows and case-sensitively on | |
| other platforms. | |
| - The function resolves symbolic links to their target paths. |
PR Summary
This pull request adds the
shallowMergefunction, including its reference documentation. Also documented thetryWhich().PR Context
Partially addresses #57.