Correctly splatting for String Tuples

I’m attempting to splat two string tuples (n and m dims) so that they create a n by m array with the combinations of every element together. So if I have

data=
       (
           ("1.20e3", "1.08e3", "0.96e3"),
           ("3.0e5", "2.7e5")
       )

Then if I apply

vec(collect.(Base.product(data...)))

I can get

6-element Vector{Vector{String}}:
 ["1.20e3", "3.0e5"]
 ["1.08e3", "3.0e5"]
 ["0.96e3", "3.0e5"]
 ["1.20e3", "2.7e5"]
 ["1.08e3", "2.7e5"]
 ["0.96e3", "2.7e5"]

This code works for any size n and m as long as they are both greater than 1. But if I have

data=
       (
           ("1.20e3", "1.08e3", "0.96e3"),
           ("3.0e5")
       )

Then I get

15-element Vector{Vector{Any}}:
 ["1.20e3", '3']
 ["1.08e3", '3']
 ["0.96e3", '3']
 ["1.20e3", '.']
 ["1.08e3", '.']
 ["0.96e3", '.']
 ["1.20e3", '0']
 ["1.08e3", '0']
 ["0.96e3", '0']
 ["1.20e3", 'e']
 ["1.08e3", 'e']
 ["0.96e3", 'e']
 ["1.20e3", '5']
 ["1.08e3", '5']
 ["0.96e3", '5']

when obviously I would like it to be

3-element Vector{Vector{String}}:
 ["1.20e3", "3.0e5"]
 ["1.08e3", "3.0e5"]
 ["0.96e3", "3.0e5"]

My understanding is that when I apply the splatting operator, it expands the single element tuple as a iterator of characters rather than an iterator of strings in a tuple.

So would anyone know how I could get the behavior that I outlined? I am working on a code that interfaces with OpenFOAM so the strings are properties of fluid variables that I need to replace in OpenFOAM text dictionaries. Thank you if you spend time on my question! Have a good day.

Hi, In your second example, ("3.0e5") is not parsed as a tuple but as a string. You’d need a comma in there ("3.0e5", )

1 Like

Yes that was it, thank you! I see now that’s directly in the documentation of Julia tuples. Sorry for the trouble.

No problems at all, sometimes we get blind about our own bugs and can spend way too long on them when a pair of fresh eyes might catch the problem in seconds.