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

Avoid using arrays and work with List<String> #768

Open
bayrakta opened this issue Sep 17, 2024 · 2 comments · Fixed by #788
Open

Avoid using arrays and work with List<String> #768

bayrakta opened this issue Sep 17, 2024 · 2 comments · Fixed by #788

Comments

@bayrakta
Copy link

As I could not find any mechanism to extend a list, I am trying to build a list of strings and work with the result in several spots to loop on it. The main idea is building a comma separated list as string and then split it by comma. However, the split method returns an array of String and I am not able to iterate on it. (The only method which works with an array is the join method, which can actually only work on a result of the split method and I don't see any meaningful use case for it.)

I would propose the following options to enhance the scripting capabilities :

  • Provide custom additional methods split and join, which work with List<String>, instead of using the ones from StringUtils.
  • Alternatively, new additional method(s) might be introduced to extend an existing list, such as extendList(List<String>, String) and appendList(List<String>, List<String>).

Sample block when the method extendList introduced :

- DEF MY_SITE_LIST=[]
- FOR siteNode IN CHILDREN OF /content:
    - DEF siteName=${siteNode.name}
    - DEF MY_SITE_LIST=${extendList(MY_SITE_LIST, siteName)}

- FOR siteName IN ${MY_SITE_LIST}:
    - DEF siteGroupName="sample-group-${siteName}"
    - ${siteGroupName}:
        - path: "/home/groups/myproject/${siteGroupName}"

P.S.: Once the improvements prepared, the last block needs to be tested. As far as I remember, the changes on MY_LIST is only in effect within the outermost FOR loop. Outside of the loop, it remains intact. This causes code duplicates, as overriding a global variable within a loop is not possible.

kwin added a commit that referenced this issue Feb 21, 2025
kwin added a commit that referenced this issue Feb 21, 2025
kwin added a commit that referenced this issue Feb 21, 2025
@kwin kwin closed this as completed in #788 Feb 22, 2025
@kwin kwin closed this as completed in d70e5e5 Feb 22, 2025
@bayrakta
Copy link
Author

Hi @kwin ,

I think this issue has been closed by mistake, as this ticket was referring to the methods exposed within the ElFunctionMapper#exportedMethods. It was about introducing two new methods, extendList and appendList respectively, as the existing methods split and join do not help much for the mentioned logic, which is illustrated in the given snippet.

Cheers,
Yunus

@kwin
Copy link
Member

kwin commented Feb 24, 2025

Indeed, sorry for that. One commit message had a wrong reference in it. I just reopened. Can you come up with a PR for this issue?

@kwin kwin reopened this Feb 24, 2025
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 a pull request may close this issue.

2 participants