Created
May 19, 2020 12:48
-
-
Save mikeacjones/dbe76e4f6f5e402e024ab57b8a2fc2b5 to your computer and use it in GitHub Desktop.
Function for easily appending namespaces to all key:value pairs of an object. Full traversal, so objects in arrays too.
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
%dw 2.0 | |
fun appendNamespace(data, nsSelector: (k: Key) -> Namespace | Null) = | |
data match { | |
case is Array -> data map appendNamespace($, nsSelector) | |
case is Object -> data mapObject do { | |
var ns0 = nsSelector($$) | |
--- | |
if (ns0 != null) ns0#"$($$)": appendNamespace($, nsSelector) | |
else ($$): appendNamespace($, nsSelector) | |
} | |
else -> data | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment