Skip to content

Instantly share code, notes, and snippets.

@mikeacjones
Last active April 19, 2023 17:22
Show Gist options
  • Save mikeacjones/a683e29fe825347148e7541bce697937 to your computer and use it in GitHub Desktop.
Save mikeacjones/a683e29fe825347148e7541bce697937 to your computer and use it in GitHub Desktop.
Function to return the power set - requires Bitwise.dwl (also in gist)
%dw 2.0
import Bitwise
fun powerSet(set: Array) = do {
var iterable = (0 to pow(2,sizeOf(set))-1) as Array
---
iterable map (item) -> set filter (Bitwise::AND(item,pow(2,$$)) != 0)
}
@mikeacjones
Copy link
Author

mikeacjones commented Apr 19, 2023

This does work; dataweave is not usually compiled. Keep in mind that you also have to include the Bitwise.dwl file.

https://gist.github.com/mikeacjones/b3c3719d38f2f075b95bd4960e2252b0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment