- From: <bugzilla@jessica.w3.org>
 - Date: Sun, 07 Feb 2016 13:34:14 +0000
 - To: public-qt-comments@w3.org
 
https://www.w3.org/Bugs/Public/show_bug.cgi?id=29428
            Bug ID: 29428
           Summary: map:fold and map:filter
           Product: XPath / XQuery / XSLT
           Version: Candidate Recommendation
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Functions and Operators 3.1
          Assignee: mike@saxonica.com
          Reporter: benito@benibela.de
        QA Contact: public-qt-comments@w3.org
  Target Milestone: ---
There is a surprising lack of higher order functions on maps. 
map:filter
Summary
    Returns an map containing those entries of the $map for which $function
returns true.
Signature
    map:filter( $map     as map(*),  $filter as function($key as
xs:anyAtomicType, $value as item()*) as xs:boolean ) as map(*)
Rules
    The effect of the function is equivalent to the following definition:
    map:merge($map, map:keys() [$filter(., $map(.))] ! map:entry(., $map(.)) )
Error Conditions
    As a consequence of the function signature and the function calling rules,
a type error occurs if the supplied function $function returns anything other
than a single xs:boolean item; there is no conversion to an effective boolean
value.
Examples
    The expression map:filter( map { "A": 1, "B": 2, "C": "Hello world" },
function($x,$y) {$y instance of xs:integer}) returns map { "A": 1, "B": 2 }.
17.3.13 map:fold
Summary
    Evaluates the supplied function cumulatively on successive values of the
supplied map.
Signature
    map:fold(   $map     as map(*),
    $zero        as item()*,
    $function    as function(item()*, xs:anyAtomicType, item()*) as item()*) as
item()*
Rules
    The effect of the function is equivalent to the following definition:
    fold-left(map:keys($map), $zero, function($aggregate as item()*, $key as
xs:anyAtomicType) as item()* { 
      $function($aggregate, $key, $map($key)) 
    })
Notes
    If the supplied map is empty, the function returns $zero.
    If the supplied map contains a single entry [$key,$value], the function
returns $zero => $function($key, $value).
    If the supplied map contains two entries [$key, $value] and [$key2,
$value2], the function returns $zero => $function($key,$value) =>
$function($key2,$value2); and similarly for an input map with more than two
entries.
Examples
    The expression map:fold(map {"a": true(), "b": true(), "c": false()},
true(), function($x, $key, $y){$x and $y}) returns false(). (Returns true if
every value of the input map has an effective boolean value of true().).
    The expression map:fold(map {"a": true(), "b": true(), "c": false()},
true(), function($x, $key, $y){$x or $y}) returns true(). (Returns true if at
least one value of the input map has an effective boolean value of true().).
-- 
You are receiving this mail because:
You are the QA Contact for the bug.
Received on Sunday, 7 February 2016 13:34:17 UTC