This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
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().).
Classifying this against future requirements. We'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.
> 17.3.13 map:fold > > 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()* 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.