diff --git a/source/com/kemsky/Stream.as b/source/com/kemsky/Stream.as index cfafbf4..5292463 100644 --- a/source/com/kemsky/Stream.as +++ b/source/com/kemsky/Stream.as @@ -424,6 +424,24 @@ package com.kemsky source[index] = value; } + /** + * Adds item to specified position. + * @param index An integer that specifies the position in the list where the item is to be added to. + * @param value An item to add. + * @example + *
+         *     var s:Stream = $(1, 2, 3);
+         *     s.addItem(1, 4);
+         *     trace(s);
+         *     //Stream{1, 4, 2, 3}
+         * 
+ * @internal mutable + */ + public function addItem(index:int, value:*):void + { + source.splice(index, 0, value); + } + /** * Executes a test function on each item and calculates number of successful tests. * @param callback The function to run on each item in the list. diff --git a/testSrc/com/kemsky/TestStream.as b/testSrc/com/kemsky/TestStream.as index ae7dac6..8fe95f4 100644 --- a/testSrc/com/kemsky/TestStream.as +++ b/testSrc/com/kemsky/TestStream.as @@ -240,6 +240,22 @@ package com.kemsky assertEquals(s[2], 1); } + + [Test] + public function testAdd():void + { + var s:Stream = $(1, 2, 3); + s.addItem(2, 1); + s.addItem(0, 3); + //3, 1, 2, 1, 3 + assertEquals(s.length, 5); + assertEquals(s[0], 3); + assertEquals(s[1], 1); + assertEquals(s[2], 2); + assertEquals(s[3], 1); + assertEquals(s[4], 3); + } + [Test] public function testGet():void {