本文整理匯總了PHP中Stream::range方法的典型用法代碼示例。如果您正苦於以下問題:PHP Stream::range方法的具體用法?PHP Stream::range怎麽用?PHP Stream::range使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Stream
的用法示例。
在下文中一共展示了Stream::range方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: range
public static function range($low = null, $high = null)
{
if ($low === null) {
$low = 1;
}
if ($low == $high) {
return Stream::make($low);
}
return new Stream($low, function () use($low, $high) {
return Stream::range($low + 1, $high);
});
}
示例2: test_scale_multiplies_stream_by_constant
public function test_scale_multiplies_stream_by_constant()
{
$capture = function ($x) use(&$vals) {
$vals[] = $x;
};
$s = Stream::range(1, 3);
$m = $s->scale(10);
$vals = array();
$m->walk($capture);
$this->assertEquals(array(10, 20, 30), $vals);
$vals = array();
$s->add($m)->walk($capture);
$this->assertEquals(array(11, 22, 33), $vals);
}
示例3: test_eratosthenes_sieve
/**
* an absolutely necessary unit test
*/
function test_eratosthenes_sieve()
{
$capture = function ($x) use(&$vals) {
$vals[] = $x;
};
function sieve($s)
{
$h = $s->head();
return new Stream($h, function () use($h, $s) {
return sieve($s->tail()->filter(function ($x) use($h) {
return $x % $h != 0;
}));
});
}
$vals = array();
sieve(Stream::range(2))->take(10)->walk($capture);
$this->assertEquals(array(2, 3, 5, 7, 11, 13, 17, 19, 23, 29), $vals);
}