Ejemplo n.º 1
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
$dump = Future\wrap('var_dump');
function isBigEnough($value)
{
    return $value >= 8;
}
$a = Future\value(array('Tom' => 8, 'Jerry' => Future\value(5), 'Spike' => 10, 'Tyke' => 3));
$dump($a->filter('isBigEnough'));
$dump($a->filter('isBigEnough', true));
Ejemplo n.º 2
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
Future\all(array(1, Future\value(2), 3))->then(function ($value) {
    var_dump($value);
});
Future\join(1, Future\value(2), 3)->then(function ($value) {
    var_dump($value);
});
Ejemplo n.º 3
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
$dump = Future\wrap('var_dump');
function isBigEnough($value)
{
    return $value >= 10;
}
$a1 = array(12, Future\value(5), 8, Future\value(130), 44);
$a2 = array(1, Future\value(5), 8, Future\value(1), 4);
$a3 = Future\value($a1);
$a4 = Future\value($a2);
$dump(Future\some($a1, 'isBigEnough'));
// true
$dump(Future\some($a2, 'isBigEnough'));
// false
$dump(Future\some($a3, 'isBigEnough'));
// true
$dump(Future\some($a4, 'isBigEnough'));
// false
Ejemplo n.º 4
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
$dump = Future\wrap('var_dump');
$numbers = Future\value(array(Future\value(0), 1, Future\value(2), 3, Future\value(4)));
function add($a, $b)
{
    return $a + $b;
}
$dump($numbers->reduce('add'));
$dump($numbers->reduce('add', 10));
$dump($numbers->reduce('add', Future\value(20)));
Ejemplo n.º 5
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
$dump = Future\wrap('var_dump');
$a = array(1, Future\value(4), 9);
$dump(Future\map($a, 'sqrt'));
Ejemplo n.º 6
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
var_dump(Future\isFuture(123));
var_dump(Future\isFuture(Future\value(123)));
Ejemplo n.º 7
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
class Test
{
    function testco($x)
    {
        (yield $x);
    }
}
$test = Future\wrap(new Test());
$test->testco(123)->then('var_dump');
$test->testco(Future\value('hello'))->then('var_dump');
Ejemplo n.º 8
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
$dump = Future\wrap('var_dump');
$numbers = array(Future\value(0), 1, Future\value(2), 3, Future\value(4));
function add($a, $b)
{
    return $a + $b;
}
$dump(Future\reduce($numbers, 'add'));
$dump(Future\reduce($numbers, 'add', 10));
$dump(Future\reduce($numbers, 'add', Future\value(20)));
Ejemplo n.º 9
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
class Test
{
    function add($a, $b)
    {
        return $a + $b;
    }
    function sub($a, $b)
    {
        return $a - $b;
    }
    function mul($a, $b)
    {
        return $a * $b;
    }
    function div($a, $b)
    {
        return $a / $b;
    }
}
$var_dump = Future\wrap('var_dump');
$test = Future\wrap(new Test());
$var_dump($test->add(1, Future\value(2)));
$var_dump($test->sub(Future\value(1), 2));
$var_dump($test->mul(Future\value(1), Future\value(2)));
$var_dump($test->div(1, 2));
Ejemplo n.º 10
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
use Hprose\Http\Client;
$test = new Client("http://hprose.com/example/");
$coroutine = Future\wrap(function ($test) {
    var_dump(1);
    var_dump((yield $test->hello("hprose")));
    $a = $test->sum(1, 2, 3);
    $b = $test->sum(4, 5, 6);
    $c = $test->sum(7, 8, 9);
    var_dump((yield $test->sum($a, $b, $c)));
    var_dump((yield $test->hello("world")));
});
$coroutine($test);
$coroutine(Future\value($test));
Ejemplo n.º 11
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
$dump = Future\wrap('var_dump');
$numbers = array(Future\value(0), 1, Future\value(2), 3, Future\value(4));
$dump(Future\search($numbers, 2));
$dump(Future\search($numbers, Future\value(3)));
$dump(Future\search($numbers, true));
$dump(Future\search($numbers, true, true));
Ejemplo n.º 12
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
$dump = Future\wrap('var_dump');
function isBigEnough($value)
{
    return $value >= 10;
}
$a1 = Future\value(array(12, Future\value(5), 8, Future\value(130), 44));
$a2 = Future\value(array(1, Future\value(5), 8, Future\value(1), 4));
$dump($a1->some('isBigEnough'));
// true
$dump($a2->some('isBigEnough'));
// false
Ejemplo n.º 13
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
$dump = Future\wrap('var_dump');
$a = Future\value(array(1, Future\value(4), 9));
$dump($a->map('sqrt'));
Ejemplo n.º 14
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
$dump = Future\wrap('var_dump');
function isBigEnough($value)
{
    return $value >= 8;
}
$a1 = array(12, Future\value(5), 8, Future\value(130), 44);
$a2 = Future\value($a1);
$dump(Future\filter($a1, 'isBigEnough'));
$dump(Future\filter($a2, 'isBigEnough'));
$a3 = array('Tom' => 8, 'Jerry' => Future\value(5), 'Spike' => 10, 'Tyke' => 3);
$a4 = Future\value($a3);
$dump(Future\filter($a3, 'isBigEnough'));
$dump(Future\filter($a3, 'isBigEnough', true));
$dump(Future\filter($a4, 'isBigEnough', true));
Ejemplo n.º 15
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
function dumpArray($value, $key)
{
    var_dump("a[{$key}] = {$value}");
}
$a1 = array(2, Future\value(5), 9);
$a2 = array('name' => Future\value('Tom'), 'age' => Future\value(18));
Future\each($a1, 'dumpArray');
Future\each($a2, 'dumpArray');
Ejemplo n.º 16
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
$p1 = new Future(function () {
    return array(Future\value(1), Future\value(2));
});
$p1->then(function ($value) {
    var_dump($value);
});
$p2 = Future\sync(function () {
    return array(Future\value(1), Future\value(2));
});
$p2->then(function ($value) {
    var_dump($value);
});
Ejemplo n.º 17
0
function value($v)
{
    return Future\value($v);
}
Ejemplo n.º 18
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
$dump = Future\wrap('var_dump');
$numbers = Future\value(array(Future\value(0), 1, Future\value(2), 3, Future\value(4)));
$dump($numbers->search(2));
$dump($numbers->search(Future\value(3)));
$dump($numbers->search(true));
$dump($numbers->search(true, true));
Ejemplo n.º 19
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
$dump = Future\wrap('var_dump');
function isBigEnough($value)
{
    return $value >= 10;
}
$a1 = Future\value(array(12, Future\value(5), 8, Future\value(130), 44));
$a2 = Future\value(array(12, Future\value(54), 18, Future\value(130), 44));
$dump($a1->every('isBigEnough'));
// false
$dump($a2->every('isBigEnough'));
// true
Ejemplo n.º 20
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
$a = array(1, Future\value(2), 3, Future\value(4), 5);
$o = new \stdClass();
$o->name = Future\value("Tom");
$o->age = Future\value(18);
Future\toFuture($a)->then(function ($value) {
    var_dump($value);
});
Future\toFuture($o)->then(function ($value) {
    var_dump($value);
});
Future\toPromise($a)->then(function ($value) {
    var_dump($value);
});
Future\toPromise($o)->then(function ($value) {
    var_dump($value);
});