Giter Site home page Giter Site logo

[FO] fn:intersperse about qtspecs HOT 9 CLOSED

qt4cg avatar qt4cg commented on June 19, 2024 2
[FO] fn:intersperse

from qtspecs.

Comments (9)

benibela avatar benibela commented on June 19, 2024

fn:intersperse($div/span, ',')

Is that really better than tail($div/span!(',', .)) ?

from qtspecs.

ChristianGruen avatar ChristianGruen commented on June 19, 2024

In the past, our users were asking for a function that works similar to fn:string-join, but can be applied to sequences. Similar to other sequence functions (including fn:head, fn:tail, fn:subsequence, fn:remove, and others that can be realized with filter expressions), the new function could make common tasks more convenient and accessible by a single function (i.e., a function in which you have to supply the input sequence only once).

An equivalent expression for the proposed function would be:

head($sequence), tail($sequence) ! ($separator, .)

from qtspecs.

michaelhkay avatar michaelhkay commented on June 19, 2024

The separator attribute on xsl:value-of has certainly been a great invention, and I've proposed adding a separator attribute to xsl:for-each, so the use case certainly exists.

The typical user today writes something like $sequence ! (., (if (position() != last()) then $separator else ())) which is very ugly, and very expensive unless optimized, and makes streamed execution difficult.

So I agree this function would be useful.

from qtspecs.

ChristianGruen avatar ChristianGruen commented on June 19, 2024

Alternative names: fn:item-join, fn:sequence-join.
What are your favorites?

from qtspecs.

michaelhkay avatar michaelhkay commented on June 19, 2024

I like "intersperse". "Join" is wrong, nothing is being joined. "Inject" would also work.

from qtspecs.

joewiz avatar joewiz commented on June 19, 2024

+1 to "intersperse" - as it suggests that something is being inserted between the items. Possibly, "interpose" or "delimit"?

from qtspecs.

ChristianGruen avatar ChristianGruen commented on June 19, 2024

In the meeting, we discussed an inverse function for fn:intersperse. Maybe https://qt4cg.org/specifications/xpath-functions-40/Overview-diff.html#func-array-partition already fills the gap?

It works slightly different at the moment, as it includes the separating item in the result, but that behavior could possibly be controlled with an additional option.

from qtspecs.

michaelhkay avatar michaelhkay commented on June 19, 2024

I found the discussion rather confusing.

If the separators are single items, the problem is trivial, just remove all the items at even-numbered positions.

Otherwise, the problem is only soluble if the separator sequence can be distinguished from the other items; you're then looking to remove all subsequences that "match" some supplied sequence. Which I guess gets us back to functions for comparing sequences (for which one approach might be a generalised deep-equal).

But could someone tell me the use case?

from qtspecs.

michaelhkay avatar michaelhkay commented on June 19, 2024

The change has been accepted and implemented. Therefore closing the issue.

from qtspecs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.