facebook / facebook/hhvm

No KeyedIteratorAggregate<Tk, Tv>?

Open
#7,692 2 comments 1 reaction 0 assignees View on GitHub
feature request hack
Dominant language
C++
Stars
18.7k
Forks
3.1k
Avg merge
1h 47m
Merged PRs (30d)
2

Description

How come there is `Iterator`, `KeyedIterator` and `IteratorAggregate`, but no `KeyedIteratorAggregate`?

Defining it and using it seems to satisfy both the typechecker and the runtime:

```php
// definition

interface KeyedIteratorAggregate<+Tk, +Tv>
extends KeyedTraversable, IteratorAggregate {
public function getIterator(): KeyedIterator;
}

// test

class Bar {
public function barMethod(): void {
echo __METHOD__, "\n";
}
}

class FooIterator implements KeyedIterator {
public function valid(): bool {
return true;
}
public function key(): Bar {
return new Bar();
}
public function current(): string {
return 'hello';
}
public function next(): void {}
public function rewind(): void {}
}

class Foo implements KeyedIteratorAggregate {
public function getIterator(): FooIterator {
return new FooIterator();
}
}

class Testtt {
public static function main(): void {
$foo = new Foo();
foreach ($foo as $k => $v) {
$k->barMethod();
}
}
}

Testtt::main();
```

```
Bar::barMethod
Bar::barMethod
Bar::barMethod
Bar::barMethod
Bar::barMethod
Bar::barMethod
...
```

### HHVM Version

```
HipHop VM 3.18.0-dev (rel)
Compiler: heads/master-0-g0f6803df27b27f929f5edc175e11d302643f3a2c
Repo schema: 1733dfccb8791a77b6ce7b894ddd66e3238c2106
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.