[Bug 29627] New: Appendix examples eg:highest, eg:lowest - proposed improvement

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

            Bug ID: 29627
           Summary: Appendix examples eg:highest, eg:lowest - proposed
                    improvement
           Product: XPath / XQuery / XSLT
           Version: Candidate Recommendation
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Functions and Operators 3.1
          Assignee: mike@saxonica.com
          Reporter: hrennau@yahoo.de
        QA Contact: public-qt-comments@w3.org
  Target Milestone: ---

The current examples assume a value getter function which maps an item to
exactly one atomic value. In practise, typical candidates for such a value
getter more often than not may also produce the empty sequence, for example due
to the rare but not impossible absence of some XML element or attribute.

Please consider making the example a little more realistic by assuming a value
getter function with this signature:
   function(item()) as xs:anyAtomicType?

The implementation of eg:higest, for example, might then look like this:

declare function eg:highest(
                     $seq as item()*, 
                     $getValue as function(item()) as xs:anyAtomicType?)
                 as item()* {
  fold-left(
    $seq,
    (),
    function($highestSoFar as item()*, $item as item()) as item()* {
      let $value := $getValue($item)
      let $highestValue := $highestSoFar[1] ! $getValue(.)
      return
        if (empty($value)) then $highestSoFar
        else if ($value > $highestValue or empty($highestSoFar)) then $item
        else if ($value = $highestValue) then ($highestSoFar, $item)
        else $highestSoFar
      }
  )
};

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

Received on Sunday, 15 May 2016 18:42:34 UTC