HH\Set::addAll
For every element in the provided Traversable
, add the value into the
current Set
public function addAll(
?Traversable<Tv> $iterable,
): Set<Tv>;
Future changes made to the original Set
ARE reflected in the returned
Set
, and vice-versa.
Parameters
?Traversable<Tv> $iterable
Returns
Set<Tv>
- Returns itself.
Examples
The following example adds a collection of values to the Set
$s
and also adds multiple collections of values to $s
through chaining. Since Set::addAll()
returns a shallow copy of $s
itself, you can chain a bunch of addAll()
calls together, and that will add all those collection of values to $s
.
$s = Set {};
// Add all the values in a Vector
$s->addAll(Vector {'a', 'b'});
// Add all the values in a Set
$s->addAll(Set {'c', 'd'});
// Add all the values in a Map
$s->addAll(Map {'foo' => 'e', 'bar' => 'f'});
// Add all the values in an array
$s->addAll(array('g', 'h'));
// Set::addAll returns the Set so it can be chained
$s->addAll(ImmSet {'i', 'j'})
->addAll(ImmVector {'k', 'l'});
var_dump($s);
object(HH\Set)#1 (12) {
string(1) "a"
string(1) "b"
string(1) "c"
string(1) "d"
string(1) "e"
string(1) "f"
string(1) "g"
string(1) "h"
string(1) "i"
string(1) "j"
string(1) "k"
string(1) "l"
}