Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3780396
D2510.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D2510.diff
View Options
diff --git a/src/Collections/BaseMap.php b/src/Collections/BaseMap.php
--- a/src/Collections/BaseMap.php
+++ b/src/Collections/BaseMap.php
@@ -3,8 +3,10 @@
namespace Keruald\OmniTools\Collections;
use ArrayAccess;
+use IteratorAggregate;
-abstract class BaseMap extends BaseCollection implements ArrayAccess {
+abstract class BaseMap extends BaseCollection
+ implements ArrayAccess, IteratorAggregate {
///
/// Methods to implement
diff --git a/src/Collections/HashMap.php b/src/Collections/HashMap.php
--- a/src/Collections/HashMap.php
+++ b/src/Collections/HashMap.php
@@ -5,7 +5,9 @@
use Keruald\OmniTools\Reflection\CallableElement;
+use ArrayIterator;
use InvalidArgumentException;
+use Traversable;
/**
* An associative array allowing the use of chained
@@ -178,4 +180,12 @@
);
}
+ ///
+ /// IteratorAggregate
+ ///
+
+ public function getIterator () : Traversable {
+ return new ArrayIterator($this->map);
+ }
+
}
diff --git a/src/Collections/Vector.php b/src/Collections/Vector.php
--- a/src/Collections/Vector.php
+++ b/src/Collections/Vector.php
@@ -7,9 +7,12 @@
use Keruald\OmniTools\Strings\Multibyte\OmniString;
use ArrayAccess;
+use ArrayIterator;
use InvalidArgumentException;
+use IteratorAggregate;
+use Traversable;
-class Vector extends BaseCollection implements ArrayAccess {
+class Vector extends BaseCollection implements ArrayAccess, IteratorAggregate {
///
/// Properties
@@ -263,4 +266,11 @@
$this->unset($offset);
}
+ ///
+ /// IteratorAggregate
+ ///
+
+ public function getIterator () : Traversable {
+ return new ArrayIterator($this->items);
+ }
}
diff --git a/tests/Collections/HashMapTest.php b/tests/Collections/HashMapTest.php
--- a/tests/Collections/HashMapTest.php
+++ b/tests/Collections/HashMapTest.php
@@ -318,4 +318,12 @@
$this->assertEquals($expected, $this->map->toArray());
}
+ ///
+ /// IteratorAggregate
+ ///
+
+ public function testGetIterator () : void {
+ $this->assertEquals(self::MAP_CONTENT, iterator_to_array($this->map));
+ }
+
}
diff --git a/tests/Collections/VectorTest.php b/tests/Collections/VectorTest.php
--- a/tests/Collections/VectorTest.php
+++ b/tests/Collections/VectorTest.php
@@ -218,4 +218,12 @@
$this->assertEquals($expected, $this->vector->toArray());
}
+ ///
+ /// IteratorAggregate
+ ///
+
+ public function testGetIterator () : void {
+ $this->assertEquals([1, 2, 3, 4, 5], iterator_to_array($this->vector));
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 13:52 (19 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2264675
Default Alt Text
D2510.diff (2 KB)
Attached To
Mode
D2510: Implement IteratorAggregate for Vector and HashMap
Attached
Detach File
Event Timeline
Log In to Comment