tremor-runtime
tremor-runtime copied to clipboard
array concatinate intrinsics
Describe the problem you are trying to solve
We have no way of adding to an array aside of array:::push and array::concatinate; those are not great from a performance standpoint, so it would be nice to think about options for this that are more intrinsic. For now we decided to handle concatenate only as it goes in line with other language constructs.
Describe the solution you'd like
TBD, the simplest option would be to allow + for arrays, where:
array + array=> concatenate- ~~
array + <not an array>=> push~~
This becomes a problem for arrays, so it's not ideal. One solution would be only to allow array + array so that it always concatenates - but performance-wise, that's also not ideal. It can be overcome, however if we treat the addition of a created array as a series of pushes.
The array + array seems to be the most sensible as we already allow it for strings. Perhaps we should extend this for binaries and arrays?
Notes
Input welcome
We could keep only the concatenation with the + operator and add an optimization that turns concatenation of a single element array literal into an append:
let base = [1, 2, 3];
let appended = base + [4];
On the other side this is not very intuitive and looks bad.
What about a special case of indexing for push?:
base[] = 4; # push
Ja I really prefer the + of arrays is only concat otherwise it leads to some very odd situations like:
let base = [[1,2], [3,4], [5,6]];
let appended = base + [7, 8];
## with + being allowed for concat and append it'd end "wrong"
I like the syntax for add perhaps we can split this in two?
+for concatinate (Array & Bytes) seems to be a fairly easy to agree on addition as it is the same as strings, we could pull this in quickly for some production perf improvements[]for append (or an alternative syntax but I like this) with a bit more consideration to ensure we don't clash with other language constructs.
I'll edit this to only cover concatinate since += will solve the append one
this is implemented