MCPcopy Create free account
hub / github.com/bazelbuild/bazel / union

Method union

src/main/java/net/starlark/java/eval/StarlarkSet.java:586–613  ·  view source on GitHub ↗
(Tuple others, StarlarkThread thread)

Source from the content-addressed store, hash-verified

584 }
585
586 @StarlarkMethod(
587 name = "union",
588 doc =
589"""
590Returns 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,
594while 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
597set.
598
599<p>For example,
600<pre class=language-python>
601set([1, 2]).union([2, 3]) # set([1, 2, 3])
602set([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",

Callers 1

binaryOpMethod · 0.45

Calls 4

toHashableCollectionMethod · 0.95
wrapOrImmutableCopyMethod · 0.95
mutabilityMethod · 0.65
addAllMethod · 0.45

Tested by

no test coverage detected