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

map(x => basename(x)) - Apply function to each value of an array #333

Closed
illusional opened this issue Sep 5, 2019 · 3 comments
Closed

Comments

@illusional
Copy link
Contributor

Hi, is there a way to apply a function to each value of an array. I'd like to get the basename (understanding there may potentially be name clashes) for each element in an array, and couldn't find a way to do this.

Other use cases, getting a bunch of strings from an array of files, eventually finding the max file-size of an array of files and more I'm sure.

If there's not a way, I think it might be something valuable you can do with some ideas:

  • Javascript-ish array.map(el => my_function(el)) or `map_elements(iterable, el => my_function(el))
  • Python-ish [my_function(el) for el in iterable]
@DavyCats
Copy link
Contributor

DavyCats commented Sep 5, 2019

There was quite a bit of discussion on such things in #312. The general consensus seemed to be that such things are best left out of the WDL syntax. Adding such features would bring WDL closer to becoming a full-blown programming language, which will reduce the ease of cooperation in the development of workflows, understanding the code written by others and learning how to write WDL. Though such a syntax might be easily understood by many programmers, WDL was intended to be intelligible and easy to learn for non-programmers as well, to whom this would likely look like magic.

Functionality like this can be achieved through the use of a task, in which you could write some (heredoc) python code. I haven't tested this but something like the following, in combination with the read_lines function, might work:

for x in ["~{sep='","' input_array}"]:
    print(do_something(x))

@jtratner
Copy link
Contributor

If you're just getting basename, why not this?

scatter(x in arr) {
   String names = basename(x)
}
call mytask (input: names=names}

and then names outside of scatter are an array of strings.

@illusional
Copy link
Contributor Author

I realised this is just a duplicate of #203, closing this.

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

No branches or pull requests

5 participants