This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 29393 - Include a convenience operator for applying a function to each item in a sequence
Summary: Include a convenience operator for applying a function to each item in a sequ...
Status: NEW
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XQuery 3.2 Use Cases and Requirements (show other bugs)
Version: Working drafts
Hardware: PC Linux
: P2 enhancement
Target Milestone: ---
Assignee: Jonathan Robie
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-26 12:03 UTC by Dirk Kirsten
Modified: 2016-01-26 19:36 UTC (History)
1 user (show)

See Also:


Attachments

Description Dirk Kirsten 2016-01-26 12:03:34 UTC
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())
Comment 1 Jonathan Robie 2016-01-26 17:33:33 UTC
I'm moving this to 3.2 (future versions).  It's too late for the current CR.
Comment 2 Michael Kay 2016-01-26 19:36:35 UTC
There's always

("a", "b", "c") => for-each(uppercase#1)