Changes

Jump to navigation Jump to search
|-
| valign='top' | '''Summary'''
|Returns its first argument unchanged and irgores the second. This function isn't useful on its own, but can be used as argument to other higher-order functions, e.g. when a function combining two values is expected and one only wants to retain the left one.
|-
| valign='top' | '''Examples'''
)
</pre>
* Another use-case: When inserting a key into a map, <code>$f</code> descides how to combine the new value with a possibly existing old one. <code>hof:const</code> here means ignoring the old value, so that's normal insertion.<pre class="brush:xquery">let $insert-with := function($f, $map, $k, $v) { let $old := $map($k), $new := if($old) then $f($v, $old) else $v return map:new(($map, map{ $k := $new })) }let $map := map{ 'foo' := 1 }let $add := $insert-with(function($a, $b) {$a + $b}, ?, ?, ?), $insert := $insert-with(hof:const#2, ?, ?, ?)return ( $add($map, 'foo', 2)('foo'), $insert($map, 'foo', 42)('foo'))</pre>returns <code>20 53 42</code>
|}
editor, reviewer
33

edits

Navigation menu