Re: fn:slice()

My favorite: fn:slice from Option C…

> fn:slice($seq, $positions as integer+)
> where $positions might be (3), (-1), (1 to 5) or ( 1 to 5 by 2).

…and, for a function-based filtering of sequences, simply a third
fn:filter argument (with a possible default value 'all'):

  fn:filter($seq, $function, $scope as xs:string)

Examples:

  filter(//div, function($div) { $div = 'Conclusion' }, 'from')
  → div element with string value 'Conclusion' and following div elements

  filter(1 to 5, -> { . = 3 }, 'before')
  → 1 2

In addition to 'before', 'until', 'from' and 'after' and 'all', we
could have 'first' (similar to Array.prototype.find() in JavaScript).
____________________________________

On Fri, Dec 4, 2020 at 11:15 AM Michael Kay <mike@saxonica.com> wrote:
>
> Which do you prefer?
>
> Option A
>
> A single (swiss-army-knife) slice() function as proposed yesterday
>
> Option B
>
> Three functions:
>
> * fn:items-at($seq, xs:integer+) returning the items at the given positions
>
> * fn:slice($seq, start?, step?,  (end | length)? ) accepting some combination of start, end, length, and step, each supplied as an integer
>
> * fn:range($seq, (before | until)? (after | from)?) accepting predicates for the start and/or end of the selected range
>
> This retains most of the useful combinations, but each of the functions is much simpler. (I've used an informal notation to indicate which combinations of parameters are allowed). Negative positions allowed for items-at, start, and end.
>
> Option C
>
> Two functions:
>
> fn:slice($seq, $positions as integer+)
>
> where $positions might be (3), (-1), (1 to 5) or ( 1 to 5 by 2).
>
> fn:range($seq, (before | until)? (after | from)?) accepting predicates for the start and/or end of the selected range
>
>
> Michael Kay
> Saxonica
>
> On 4 Dec 2020, at 03:52, Mukul Gandhi <gandhi.mukul@gmail.com> wrote:
>
> On Fri, Dec 4, 2020 at 8:04 AM Dimitre Novatchev <dnovatchev@gmail.com> wrote:
>>
>> While this function is obviously very powerful, its complexity affects the learning and confidence of use.
>>
>> This leads to not-confident / hesitant / unhappy developers.
>
>
> I agree to above mentioned concerns.
>
> But +1 to introduction of fn:slice() function to XPath/XSLT.
>
>
>
> --
> Regards,
> Mukul Gandhi

Received on Friday, 4 December 2020 11:56:48 UTC