Skip to content

Instantly share code, notes, and snippets.

@adamretter
Created July 27, 2022 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamretter/7d90a7e550ea7588d0684fbf45dacdd5 to your computer and use it in GitHub Desktop.
Save adamretter/7d90a7e550ea7588d0684fbf45dacdd5 to your computer and use it in GitHub Desktop.
flatten-array.xqm
declare function local:flatten-once($ar as array(*)) as array(*) {
array:fold-left($ar, array{}, function($x, $y){
array:join(($x,
if ($y instance of array(*))
then
array { $y?* }
else
array { $y } (: for array(t) -> array(t) :)
))
})
};
local:flatten-once([[[1,2], [3,4]]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment