interface ObjectCollection<+T as object> extends IteratorAggregate {} function foo(): vec { return vec[1, 2, 3]; } function bar(): dict { return dict['a' => 1, 'b' => 2, 'c' => 3]; } function baz(bool $a): iterable { if $a { return vec[1, 2, 3]; } else { return dict[1 => 1, 2 => 2, 3 => 3]; } } final class Box { public function __construct(public T $value) {} } function box(): Box> { return new Box(vec[1, 2, 3]); } function unbox(Box> $box): vec { return $box->value; } function foo(bool $a, bool $b): vec|dict|Box> { if $a { return vec[1, 2, 3]; } else if $b { return dict['a' => 1, 'b' => 2, 'c' => 3]; } else { return new Box(vec[1, 2, 3]); } } function into_vec(iterable<_, Tv> $iterable): vec { $vec = vec[]; foreach $iterable as $value { $vec[] = $value; } return $vec; } function into_dict(iterable $iterable): dict { $dict = dict[]; foreach $iterable as $key => $value { $dict[$key] = $value; } return $dict; } function baz(): void { $dict = dict[1 => 1, 2 => 2, 3 => 3]; $vec = vec[1, 2, 3]; $dict2 = into_dict::($vec); $vec2 = into_vec::($dict); $a = vec[$dict1, $dict2]; $b = into_dict::>($a); $c = new Box::>>($b); }