예제 #1
0
 public function testMap()
 {
     $seq = new Sequence();
     $seq->add('a');
     $seq->add('b');
     $self = $this;
     $newSeq = $seq->map(function ($elem) use($self) {
         switch ($elem) {
             case 'a':
                 return 'c';
             case 'b':
                 return 'd';
             default:
                 $self->fail('Unexpected element: ' . var_export($elem, true));
         }
     });
     $this->assertInstanceOf('PhpCollection\\Sequence', $newSeq);
     $this->assertNotSame($newSeq, $seq);
     $this->assertEquals(array('c', 'd'), $newSeq->all());
 }