diff --git a/source/com/kemsky/Iterator.as b/source/com/kemsky/Iterator.as index 4e01c4e..bb4e3d9 100644 --- a/source/com/kemsky/Iterator.as +++ b/source/com/kemsky/Iterator.as @@ -88,7 +88,7 @@ package com.kemsky _next--; } - stream.removeItem(_current); + stream.removeItemAt(_current); _current = -1; } diff --git a/source/com/kemsky/Stream.as b/source/com/kemsky/Stream.as index bfa6892..696246c 100644 --- a/source/com/kemsky/Stream.as +++ b/source/com/kemsky/Stream.as @@ -598,13 +598,13 @@ package com.kemsky * @example *
          *     var s:Stream = $(1, 2, 3);
-         *     s.removeItem(0);
+         *     s.removeItemAt(0);
          *     trace(s);
          *     //Stream{2, 3}
          * 
* @internal mutable */ - public function removeItem(index:int):Boolean + public function removeItemAt(index:int):Boolean { if(index < 0) { @@ -616,6 +616,29 @@ package com.kemsky } } + /** + * Removes item (using strict equals ===). + * @param item target item. + * @return true if remove was successful. + * @example + *
+         *     var s:Stream = $(1, 2, 3);
+         *     s.removeItem(1);
+         *     trace(s);
+         *     //Stream{2, 3}
+         * 
+ * @internal mutable + */ + public function removeItem(item:*):Boolean + { + var index:int = source.indexOf(item); + if(index >= 0) + { + return (source.splice(index, 1) as Array).length > 0; + } + return false; + } + /** * 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. @@ -1591,7 +1614,7 @@ package com.kemsky { if(callback(result.getItem(i), result.getItem(j))) { - result.removeItem(j); + result.removeItemAt(j); } } } @@ -1604,7 +1627,7 @@ package com.kemsky { if(result.getItem(i) === result.getItem(j)) { - result.removeItem(j); + result.removeItemAt(j); } } } @@ -2304,7 +2327,7 @@ package com.kemsky return false; } - return removeItem(index); + return removeItemAt(index); } /** diff --git a/testSrc/com/kemsky/TestStream.as b/testSrc/com/kemsky/TestStream.as index 7780725..f0d67f9 100644 --- a/testSrc/com/kemsky/TestStream.as +++ b/testSrc/com/kemsky/TestStream.as @@ -517,21 +517,33 @@ package com.kemsky assertTrue(s.getItem(3) === undefined); } - [Test] public function testRemove():void { var s:Stream = $(1, 2, 3); - s.removeItem(0); s.removeItem(1); + s.removeItem(3); + assertEquals(s.length, 1); + assertEquals(s[0], 2); + + var result:Boolean = new Stream().removeItem(1); + assertEquals(result, false); + } + + [Test] + public function testRemoveAt():void + { + var s:Stream = $(1, 2, 3); + s.removeItemAt(0); + s.removeItemAt(1); assertEquals(s.length, 1); assertEquals(s[0], 2); - var result:Boolean = s.removeItem(-1); + var result:Boolean = s.removeItemAt(-1); assertEquals(s.length, 0); assertEquals(result, true); - assertEquals(s.removeItem(0), false); + assertEquals(s.removeItemAt(0), false); } [Test]