Exemple #1
0
/**
 * @param Collection $xs
 * @param integer $result
 * @param \Closure $f
 * @return integer
 */
function iterateCollection(Collection $xs, $result, $f)
{
    if (!$xs->isEmpty()) {
        return iterateCollection($xs->tail(), $f($xs->head()) + $result, $f);
    } else {
        return $result;
    }
}
Exemple #2
0
 public function testHeadTail()
 {
     $collection = new Collection([1, 2, 3, 4]);
     self::assertEquals(1, $collection->head());
     self::assertCount(3, $collection->tail());
 }