Last active
August 11, 2022 21:14
-
-
Save line-o/9ac314dde4b77f2d079d43539de035ee to your computer and use it in GitHub Desktop.
array:flatten is recursive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare function local:flatten-one($nested as array(*)) as array(*) { | |
array:fold-left($nested, [], function ($flattened as array(*), $next as item()*) as array(*) { | |
typeswitch($next) | |
case array(*) return array:join(($flattened, $next)) | |
default return array:append($flattened, $next) | |
}) | |
}; | |
local:flatten-one([[1], 3, map{}, [1, [3,4]], ()]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment