Skip to content

Commit

Permalink
add item
Browse files Browse the repository at this point in the history
  • Loading branch information
kemsky committed Nov 9, 2015
1 parent 596059d commit 88f838a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
18 changes: 18 additions & 0 deletions source/com/kemsky/Stream.as
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <pre>
* var s:Stream = $(1, 2, 3);
* s.addItem(1, 4);
* trace(s);
* //Stream{1, 4, 2, 3}
* </pre>
* @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.
Expand Down
16 changes: 16 additions & 0 deletions testSrc/com/kemsky/TestStream.as
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 88f838a

Please sign in to comment.