(Tuple others, StarlarkThread thread)
| 584 | } |
| 585 | |
| 586 | @StarlarkMethod( |
| 587 | name = "union", |
| 588 | doc = |
| 589 | """ |
| 590 | Returns a new mutable set containing the union of this set with others. |
| 591 | |
| 592 | <p>If <code>s</code> and <code>t</code> are sets, <code>s.union(t)</code> is equivalent to |
| 593 | <code>s | t</code>; however, note that the <code>|</code> operation requires both sides to be sets, |
| 594 | while the <code>union</code> method also accepts sequences and dicts. |
| 595 | |
| 596 | <p>It is permissible to call <code>union</code> without any arguments; this returns a copy of the |
| 597 | set. |
| 598 | |
| 599 | <p>For example, |
| 600 | <pre class=language-python> |
| 601 | set([1, 2]).union([2, 3]) # set([1, 2, 3]) |
| 602 | set([1, 2]).union([2, 3], {3: "a", 4: "b"}) # set([1, 2, 3, 4]) |
| 603 | </pre> |
| 604 | """, |
| 605 | extraPositionals = @Param(name = "others", doc = "Collections of hashable elements."), |
| 606 | useStarlarkThread = true) |
| 607 | public StarlarkSet<?> union(Tuple others, StarlarkThread thread) throws EvalException { |
| 608 | LinkedHashSet<Object> newContents = new LinkedHashSet<>(contents); |
| 609 | for (Object other : others) { |
| 610 | newContents.addAll(toHashableCollection(other, "union argument")); |
| 611 | } |
| 612 | return wrapOrImmutableCopy(thread.mutability(), newContents); |
| 613 | } |
| 614 | |
| 615 | @StarlarkMethod( |
| 616 | name = "intersection", |
no test coverage detected