Given is a config of apps and containers with an app being able to have multiple containers a container being able to have multiple apps. I want to be able to output them in 2 ways
- Per app list the containers
- Per container list the apps
The data format is simple, but I can't seem to find a way to get both of these representations without repeating the relation.
Example data when starting from containers having apps
let app1 = { name = "app1" }
let app2 = { name = "app2" }
let containers = [
{ name = "container1", apps = [ app1 ] },
{ name = "container2", apps = [ app1, app2 ] }
]
{- I can easily transform this data to the following -}
[
{ app = "app1", container = "container1" },
{ app = "app1", container = "container2" },
{ app = "app2", container = "container2" }
]
{- But I cannot seem to get it into the requested format -}
[
"app1" = [ "container1", "container2" ]
"app2" = [ "container2" ]
]
I think using identifiers as Text
cannot work as there is no way to merge associated lists or something alike using equal identifiers.
Using records I can merge something like this {a1 = {c1 = True}} /\ {a1 = {c2 = True}} /\ {a2 = {c2 = True}}
. Which would be {a1 = {c1 = True, c2 = True}, a2 = {c2 = True}}
.
But I can't get to this state in the first place because I can't 'reverse' records.
I don't care how I need to structure the config as long as I don't need to repeat the relation twice.