Skip to content

Commit

Permalink
removed arrayaccess, added __invoke as a shortcut for Stream::item( )
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Gantt committed Sep 16, 2011
1 parent 57bc9f6 commit f753846
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
23 changes: 2 additions & 21 deletions stream.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class Stream implements Iterator, ArrayAccess {
class Stream implements Iterator {
private $tailPromise;
private $headValue;
private $pointer;
Expand Down Expand Up @@ -39,29 +39,10 @@ public function valid() {
}
/* end of iterator methods */

/* arrayaccess methods */
public function offsetGet( $n ) {
public function __invoke( $n ) {
return $this->item( $n );
}

public function offsetExists( $n ) {
try {
$this->item( $n );
} catch( Exception $e ) {
return false;
}
return true;
}

public function offsetSet( $n, $v ) {
// how to reconcile with a tailpromise?
}

public function offsetUnset( $n ) {
// do some cleverness with Stream->drop( $n )?
}
/* end of arrayaccess methods */

public function blank() {
return ( $this->headValue === null );
}
Expand Down
6 changes: 3 additions & 3 deletions test/finite_stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public function test_has_correct_values() {

public function test_array_access_gives_correct_values() {
$s = $this->make_static_stream();
$this->assertEquals( 10, $s[0] );
$this->assertEquals( 20, $s[1] );
$this->assertEquals( 30, $s[2] );
$this->assertEquals( 10, $s(0) );
$this->assertEquals( 20, $s(1) );
$this->assertEquals( 30, $s(2) );
}

public function test_car_cdr_behavior() {
Expand Down

0 comments on commit f753846

Please sign in to comment.