1

I want to concatenate two tuples in the way similar to concatenating vectors. For example, I have two tuples: a=(1,2,3) and b=(4,5,6), and I want to use join to obtain re=(1,2,3,4,5,6). However, the output is (1,2,3,(4,5,6)), which is same as the result of a.append!(b). How could I modify my script?

Polly
  • 603
  • 3
  • 13
  • Never used DolphinDB. What about union? https://www.dolphindb.com/help/FunctionsandCommands/FunctionReferences/u/union.html. – Allan Wind Jun 30 '23 at 01:48

2 Answers2

2

The join function alone won't return the desired result because it treats the second tuple b as a single element. You can use it within the reduce function:

a1= (0,[1,2,3],4)
a2 = ([5,6], 7)
reduce(join, a2, a1)
Eva Gao
  • 402
  • 1
  • 7
0

Both join and union can not work on tuples. You can try:

  1. flatten((a, b)) to create a new tuple with elements in a and b;
  2. each(append!{a}, b) to add every element in b into a.
Hanwei Tang
  • 413
  • 3
  • 10