本文整理汇总了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);
}