Skip to content
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

port: extend merge built-in function #3858

Merged
merged 1 commit into from
Jul 9, 2021
Merged

port: extend merge built-in function #3858

merged 1 commit into from
Jul 9, 2021

Conversation

Danieladu
Copy link
Contributor

Fixes #3857

Description

extend merge built-in function

Specific Changes

Originally, merge only accepts objects.
For example:
merge({}, {k1:'v1'}, {k2:'v2', k3:'v3'})

but sometimes the input is an array, and there is no way to convert the array into a list of objects.
The solution is to change the merge function to accept array type as well.

The logic is, if the item is array, merge its object children.

For example:
merge({k1:'v1'}, [{k2:'v2'}, {k3: 'v3'}], {k4:'v4'})

The second item is array, if we follows the previous practice, would get en error which shows the input only accepts "structure object", but not array. But now, you would get the right result:
{ ​"k1":"v1", ​"k2":"v2", ​"k3":"v3", "k4":"v4"}

But it should be noted that, the flatten operator would be applied for only once. If the array is nested, exception would be thrown too.

For example:
merge([{k1:'v1'}, {k2:'v2'}]) -> ok
merge([{k1:'v1'}, [{k2:'v2'}]]) -> the item of the array should be an object.

Doc change

add [Doc should change] mark

@Danieladu Danieladu requested review from a team as code owners July 9, 2021 04:21
@Danieladu Danieladu requested review from Stevenic and chrimc62 July 9, 2021 04:21
@coveralls
Copy link

coveralls commented Jul 9, 2021

Pull Request Test Coverage Report for Build 1013968478

  • 22 of 23 (95.65%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 84.344%

Changes Missing Coverage Covered Lines Changed/Added Lines %
libraries/adaptive-expressions/src/builtinFunctions/merge.ts 22 23 95.65%
Totals Coverage Status
Change from base Build 1013051675: 0.003%
Covered Lines: 19684
Relevant Lines: 22142

💛 - Coveralls

@joshgummersall joshgummersall merged commit 7afa288 into main Jul 9, 2021
@joshgummersall joshgummersall deleted the hond/merge branch July 9, 2021 15:42
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.

port: extend merge built-in function (#5742)
3 participants