/** * This method tests the "take" method. * * @dataProvider data_take */ public function test_take(array $provided, array $expected) { $p0 = ILinkedList\Type::make($provided[0], '\\Saber\\Data\\IInt32\\Type'); $p1 = IInt32\Type::box($provided[1]); $r0 = ILinkedList\Module::take($p0, $p1); $e0 = $expected[0]; $this->assertInstanceOf('\\Saber\\Data\\ILinkedList\\Type', $r0); $this->assertSame($e0, $r0->unbox(1)); }
/** * This method returns the first "n" items in the list. * * @access public * @static * @param ILinkedList\Type $xs the left operand * @param IInt32\Type $n the number of items to take * @return ILinkedList\Type the list */ public static function take(ILinkedList\Type $xs, IInt32\Type $n) : ILinkedList\Type { if ($n->unbox() <= 0 || $xs->__isEmpty()) { return ILinkedList\Type::nil(); } return ILinkedList\Type::cons($xs->head(), ILinkedList\Module::take($xs->tail(), IInt32\Module::decrement($n))); }