qt4cg / qtspecs

QT4 specifications
https://qt4cg.org/
Other
28 stars 15 forks source link

fn:intersperse → fn:join, array:join($arrays, $separator) #868

Open ChristianGruen opened 9 months ago

ChristianGruen commented 9 months ago

With string-join, you can create a string for multiple strings, optionally interspersed with a separator. array:join can be used to create an array from multiple arrays.

fn:intersperse, which has been added to the XQuery 4 draft, does something very similar, and early feedback indicates that the function is useful, but easily to overlook due to its name.

I propose to unify the functions by…

  1. renaming fn:intersperse to fn:join;
  2. adding a parameter to array:join: $separator as array(*)* := (); and
  3. allowing a separator sequence for fn:string-join: $separator as xs:string* := ().

Examples

Query Result Info
string-join(('1','2','3'), '-') '1-2-3' existing syntax
array:join([[1],[2],[3]], ['-']) [1,'-',2,'-',3] new
join((1,2,3), '-') (1,'-',2,'-',3) now: intersperse((1,2,3),'-')
string-join(('1','2','3')) '123' existing syntax
array:join([[1],[2],[3]]) [1,2,3] existing syntax
join((1,2,3)) (1,2,3) now: intersperse((1,2,3))
(or just (1,2,3))
string-join(('1','2','3'), ('-','+') '1-+2-+3' new
array:join([[1],[2],[3]], ['-','+']) [1,'-','+',2,'-','+',3] new
join((1,2,3), ('-','+')) (1,'-','+',2,'-','+',3) now: intersperse((1,2,3),('-','+'))
benibela commented 9 months ago

renaming fn:intersperse to fn:join;

Could also call it sequence-join or items-join, then it is more consistent with string-join

items-join variant would also be consistent with items-after

adding a parameter to array:join: $separator as array() := (); and

or it could be a sequence.

array:join([1,2,3], '-') to make it [1,'-',2,'-',3]

ChristianGruen commented 9 months ago

Could also call it sequence-join or items-join, then it is more consistent with string-join

I suggested fn:join as we already have array:join and various other sequence functions that don’t include sequence.

items-join variant would also be consistent with items-after

The items- functions will probably be renamed:

https://qt4cg.org/pr/855/xpath-functions-40/Overview.html#func-subsequence-after https://github.com/qt4cg/qtspecs/issues/844#issuecomment-1826276165

or it could be a sequence. array:join([1,2,3], '-') to make it [1,'-',2,'-',3]

I thought about this, but then it wouldn’t be possible to include multiple arrays.

joewiz commented 9 months ago

+1 to fn:join (and array:join)

michaelhkay commented 9 months ago

I'm still a little uneasy that for many people with a database background, join means relational equijoin.

ChristianGruen commented 1 month ago

I noticed that during XML Prague the PRG-required label was added to this issue.

Does someone remember which of my suggestions were regarded as necessary? Would it be helpful if I create a PR for my initial proposal?

michaelhkay commented 1 month ago

Does someone remember

Not I, I'm afraid.