> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/s/set_consolidation.md).

# Set consolidation

```ruby
func consolidate() { [] }
func consolidate(this, *those) {
    gather {
        consolidate(those...).each { |that|
            if (this & that) { this |= that }
            else             { take that }
        }
        take this
    }
}
 
enum |A="A", B, C, D, _E, F, G, H, I, _J, K|
 
func format(ss) {
    ss.map{ '(' + .join(' ') + ')' }.join(' ')
}
 
[
    [[A,B], [C,D]],
    [[A,B], [B,D]],
    [[A,B], [C,D], [D,B]],
    [[H,I,K], [A,B], [C,D], [D,B], [F,G,H]]
].each { |ss|
    say (format(ss), "\n\t==> ", format(consolidate(ss...)))
}
```

#### Output:

```
(A B) (C D)
    ==> (C D) (A B)
(A B) (B D)
    ==> (A B D)
(A B) (C D) (D B)
    ==> (A B C D)
(H I K) (A B) (C D) (D B) (F G H)
    ==> (A B C D) (H I K F G)
```
