Skip to content

Instantly share code, notes, and snippets.

@line-o
Last active July 3, 2018 15:49
Show Gist options
  • Select an option

  • Save line-o/d15bfcc1f38007ce62e075012612d8dc to your computer and use it in GitHub Desktop.

Select an option

Save line-o/d15bfcc1f38007ce62e075012612d8dc to your computer and use it in GitHub Desktop.
Working with sequences and the arrow operator I noticed that filter function cannot be used directly after the arrow operator. Tested in exist-db 4.1.0
xquery version "3.1";
declare function local:plusOne ($a as xs:integer) { $a + 1 };
declare function local:greaterThanFive ($a as xs:integer) { $a > 5 };
declare function local:eachPlusOne ($s as xs:integer*) {
for-each($s, local:plusOne#1)
};
declare function local:filterGreaterThanFive ($s as xs:integer*) {
filter($s, local:greaterThanFive#1)
};
let $funcref1 := local:plusOne#1
let $funcref2 := local:greaterThanFive#1
let $funcref3 := local:eachPlusOne#1
let $funcref4 := local:filterGreaterThanFive#1
(:
: the following two ways to operate on sequences with the arrow operator do
: work but require to wrap the calls to for-each and filter in a function
:)
return
(0 to 9)
=> local:eachPlusOne#1
=> local:filterGreaterThanFive#1
(:
=> $funcref3(?)
=> $funcref4(?)
:)
(: nicer way of writing would be :)
(:
=> for-each(?, local:plusOne#1)
=> filter(?, local:greaterThanFive#1)
:)
(: or :)
(:
=> for-each(?, $funcref1(?))
=> filter(?, $funcref2(?))
:)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment