<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>29428</bug_id>
          
          <creation_ts>2016-02-07 13:34:14 +0000</creation_ts>
          <short_desc>map:fold and map:filter</short_desc>
          <delta_ts>2016-05-22 06:40:15 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XQuery 3.2 Use Cases and Requirements</component>
          <version>Candidate Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Benito van der Zander">benito</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</assigned_to>
          <cc>vladimir</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>124887</commentid>
    <comment_count>0</comment_count>
    <who name="Benito van der Zander">benito</who>
    <bug_when>2016-02-07 13:34:14 +0000</bug_when>
    <thetext>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 { &quot;A&quot;: 1, &quot;B&quot;: 2, &quot;C&quot;: &quot;Hello world&quot; }, function($x,$y) {$y instance of xs:integer}) returns map { &quot;A&quot;: 1, &quot;B&quot;: 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 =&gt; $function($key, $value).

    If the supplied map contains two entries [$key, $value] and [$key2, $value2], the function returns $zero =&gt; $function($key,$value) =&gt; $function($key2,$value2); and similarly for an input map with more than two entries.
    
Examples

    The expression map:fold(map {&quot;a&quot;: true(), &quot;b&quot;: true(), &quot;c&quot;: 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 {&quot;a&quot;: true(), &quot;b&quot;: true(), &quot;c&quot;: 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().).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124889</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-02-07 13:55:08 +0000</bug_when>
    <thetext>Classifying this against future requirements. We&apos;re not going to be adding anything to 3.1 just because it seems a good idea; the bar for considering changes to a candidate recommendation has to be set very high.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126475</commentid>
    <comment_count>2</comment_count>
    <who name="Vladimir Nesterovsky">vladimir</who>
    <bug_when>2016-05-22 06:40:15 +0000</bug_when>
    <thetext>&gt; 17.3.13 map:fold
&gt; 
&gt;     Evaluates the supplied function cumulatively on successive values of the
&gt; supplied map.
&gt;     
&gt; Signature
&gt;     map:fold(	$map	 as map(*),
&gt;     $zero	 as item()*,
&gt;     $function	 as function(item()*, xs:anyAtomicType, item()*) as item()*)
&gt; as item()*

Please note that map:fold() would be of limited use, as with current definitions it relies on map:keys() functions, which is non-deterministic with respect to ordering. This means that two calls with the same argument are not guaranteed to call $function in the same order.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>