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

Is there any support for join/concat #90

Closed
echesakov opened this issue Dec 21, 2018 · 11 comments
Closed

Is there any support for join/concat #90

echesakov opened this issue Dec 21, 2018 · 11 comments
Assignees
Labels
enhancement New feature or request

Comments

@echesakov
Copy link

Is it possible now to join the elements of sequence to a string?

items:
- foo
- bar

result: ${{ join(items, ';') }}

where result would contain foo;bar string

One of possible scenarios for this could specifying MSBuild semicolon-separated property values using array syntax (instead of a very long string)

@echesakov
Copy link
Author

/cc @sbomer @chcosta

@vtbassmatt
Copy link
Member

@ericsciple this seems like a decent addition to the expression language. Unless we already have something that will satisfy their scenario? (See the link above.)

@echesakov
Copy link
Author

/cc @RussKeldorph

@ericsciple
Copy link
Contributor

I briefly discussed with @vtbassmatt and understand the scenario better now. Makes sense. I'll discuss further with Matt, so we can nail down the details in a spec somewhere (not strictly yaml; the core expression functions are available in other parts of the system too)

@echesakov
Copy link
Author

@ericsciple Thank you for considering to add this feature!

Can't wait to have this in any form in the language and remove ugly workaround introduced by dotnet/coreclr#22173

@ericsciple ericsciple self-assigned this Feb 5, 2019
@ericsciple ericsciple added the enhancement New feature or request label Feb 5, 2019
@ericsciple
Copy link
Contributor

@vtbassmatt @echesakovMSFT @sbomer @chcosta what do you think about this proposed behavior:

Join function

  • Concatenates all elements in the right parameter array, separated by the left parameter string.
  • Min parameters: 2. Max parameters: 2
  • Each element in the array is converted to string. Complex objects are converted to empty string.
  • If the right parameter is not an array, the result is empty string.

Or would this behavior be better:

  • If the right parameter is not an array, the result is the right parameter converted to a string.

@echesakov
Copy link
Author

I like the second behavior for the right parameter. In this case, I can think about the function as the following two steps transformation:

  1. Convert the right parameter to an array of strings. If the original value is not an array, treat it as a singleton array (of one item).
  2. Join the resulting array of strings using the left parameter.

@vtbassmatt
Copy link
Member

Yeah, now that you mention it, the silent conversion to an empty string would be confusing.

@ericsciple
Copy link
Contributor

This will roll out with the m148 payload.

@jontreynes
Copy link

Is there any support to have an append to array. I see the support here converts an array to a string with a delimiter. However, the use case I'm looking for is to append to an array.

For example

- name: dependsOn
   default:
     - stage1
     - stage2
- name: additionalDependsOn   
    default: stage0
    
 result: ${{append(parameters.dependsOn, additionalDependsOn)}}
 
 # where result is an array [stage1, stage2, stage0]
     

@jontreynes
Copy link

Is there any support to have an append to array. I see the support here converts an array to a string with a delimiter. However, the use case I'm looking for is to append to an array.

For example

- name: dependsOn
   default:
     - stage1
     - stage2
- name: additionalDependsOn   
    default: stage0
    
 result: ${{append(parameters.dependsOn, additionalDependsOn)}}
 
 # where result is an array [stage1, stage2, stage0]
     

Update: I've added to feature requests here https://developercommunity.visualstudio.com/t/Function-to-append-to-a-yaml-Array/10166131?space=21&q=function+to+add+to+yaml+array&entry=myfeedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants