Skip to content

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

Closed

Description

@ChristianGruen

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)) '12' existing syntax
string-join((1, 2), '-') '1-2 existing syntax
string-join((1, 2), ('-', '+')) '1-+2' new
array:join([ [ 1 ], [ 2 ] ]) [ 1, 2 ] existing syntax
array:join([ [ 1 ], [ 2 ] ], [ '-' ]) [ 1, '-', 2 ] new
array:join([ [ 1 ], [ 2 ] ], [ '-', '+' ]) [ 1, '-', '+', 2 ] new
join((1, 2)) (1, 2) intersperse((1, 2))
(or just (1, 2))
join((1, 2), '-') (1, '-', 2) intersperse((1, 2), '-')
join((1, 2), ('-', '+')) (1, '-', '+', 2) intersperse((1, 2), ('-', '+'))

Activity

  1. added
    XQFOAn issue related to Functions and Operators
    EnhancementA change or improvement to an existing feature
    on Dec 4, 2023
  2. benibela commented on Dec 4, 2023

    @benibela

    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]

  3. ChristianGruen commented on Dec 4, 2023

    @ChristianGruen
    ContributorAuthor

    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
    #844 (comment)

    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.

  4. joewiz commented on Dec 4, 2023

    @joewiz
    Contributor

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

  5. michaelhkay commented on Dec 5, 2023

    @michaelhkay
    Contributor

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

  6. added
    PRG-easyCategorized as "easy" at the Prague f2f, 2024
    PRG-optionalCategorized as "optional for 4.0" at the Prague f2f, 2024
    PRG-requiredCategorized as "required for 4.0" at the Prague f2f, 2024
    and removed
    PRG-optionalCategorized as "optional for 4.0" at the Prague f2f, 2024
    on Jun 4, 2024
  7. ChristianGruen commented on Aug 1, 2024

    @ChristianGruen
    ContributorAuthor

    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?

  8. michaelhkay commented on Aug 1, 2024

    @michaelhkay
    Contributor

    Does someone remember

    Not I, I'm afraid.

  9. added a commit that references this issue on Oct 16, 2024
    c623a31
  10. added 6 commits that reference this issue on Oct 24, 2024
    3a1b71e
    a9c9302
    fa7d49e
    9fad983
    099665e
    99e24de
  11. removed their assignment
    on Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementA change or improvement to an existing featurePRG-easyCategorized as "easy" at the Prague f2f, 2024PRG-requiredCategorized as "required for 4.0" at the Prague f2f, 2024XQFOAn issue related to Functions and Operators

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions