[Bug 29393] New: Include a convenience operator for applying a function to each item in a sequence

https://www.w3.org/Bugs/Public/show_bug.cgi?id=29393

            Bug ID: 29393
           Summary: Include a convenience operator for applying a function
                    to each item in a sequence
           Product: XPath / XQuery / XSLT
           Version: Working drafts
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: XQuery 3.1
          Assignee: jonathan.robie@gmail.com
          Reporter: dk@basex.org
        QA Contact: public-qt-comments@w3.org
  Target Milestone: ---

XQuery 3.1 introduces the arrow operator to apply a function to an item in a
much more readable way. In the same spirit, I would like to apply a function to
items in a sequence in such a nice and easily readable way. 

Suppose, we have a sequence ("a", "b", "c") and we want to get a sequence of
upper-case letters as a result. So using the ! operator we can get each item in
the sequence and using the arrow operator we can apply the upper-case function.
This will result in the following code:

  ("a", "b", "c") ! (. => upper-case())

which isn't really easier readable anymore because of the required parenthesis.
It would be much nicer if we could add an operator, lets say ==>, which would
apply the function for each item in the sequence, so we would simply write:

  ("a", "b", "c") ==> upper-case()

This gets even more relevant if the expression is longer. Lets take the example
from the spec for the arrow operator at
https://www.w3.org/TR/2014/WD-xquery-31-20140424/#id-arrow-operator:

  tokenize((normalize-unicode(upper-case($string))),"\s+")

Suppose, instead of a $string we have a $sequence. Currently, we would have to
write:

  $item ! (. =>upper-case()=>normalize-unicode()=>tokenize("\s+"))

With a new operator this would change to

  $item==>upper-case()=>normalize-unicode()=>tokenize("\s+")

which removes difficult to read and nested parenthesis.

So to sum up, this double arrow operator is a postfix operator that applies a
function to each item in a seuqnece, using each item as the first argument to
the function.] If $s is a sequence and f() is a function, then $s==>f() is
equivalent to $s ! f(.) or $s ! (. => f())

-- 
You are receiving this mail because:
You are the QA Contact for the bug.

Received on Tuesday, 26 January 2016 12:03:37 UTC