Exemple #1
0
<?php

require_once 'List/RubyLike.php';
$list =& new List_RubyLike(array("foo", "bar", "baz"));
$list->push("bab")->push("moge", "piyo")->unshift("hoge")->each(function ($v) {
    print $v . "\n";
});
print $list->join(",") . "\n";
print "first: " . $list->first() . "\n";
print "last: " . $list->last() . "\n";
$list->slice(2, 2)->dump();
$list->each_index(function ($i) {
    print $i . "\n";
});
$list->map(function ($v) {
    return strtoupper($v);
})->each(function ($v) {
    print $v . "\n";
});
$list->grep(function ($v) {
    return strlen($v) > 3;
})->dump();
print $list->find(function ($v) {
    return strstr($v, "ho");
}) . "\n";
print $list->length() . "\n";
print LR(array(2, 4, 5))->reduce(function ($a, $b) {
    return $a + $b;
}) . "\n";
print LR(array(2, 4, 5))->sum() . "\n";
Exemple #2
0
Fichier : pq.php Projet : naoya/PQ
 public function exec()
 {
     $db = MDB2::connect($this->_dsn);
     list($sql, $binds) = $this->to_sql();
     // echo $sql . "\n";
     $st = $db->prepare($sql);
     $rs = $st->execute($binds);
     $rows = $rs->fetchAll();
     return LR($rows);
 }
Exemple #3
0
$t->ok($list);
$t->is($list->length(), 5);
$t->is($list->first(), 2);
$t->is($list->last(), 10);
$t->is($list->sum(), 30);
$t->is($list->pop(), 10);
$t->is_deeply($list->to_a(), array(2, 4, 6, 8));
$t->is($list->shift(), 2);
$t->is_deeply($list->to_a(), array(4, 6, 8));
$t->is(get_class($list->push(5)), 'List_RubyLike');
$t->is($list->last(), 5);
$t->is_deeply($list->to_a(), array(4, 6, 8, 5));
$t->is(get_class($list->unshift(10)), 'List_RubyLike');
$t->is($list->first(), 10);
$t->is_deeply($list->to_a(), array(10, 4, 6, 8, 5));
$t->is($list->join(","), "10,4,6,8,5");
$t->is_deeply($list->slice(2, 2)->to_a(), array(6, 8));
$t->is_deeply($list->unshift(1, 2)->to_a(), array(1, 2, 10, 4, 6, 8, 5));
$list2 = new List_RubyLike(1, 2, 3);
$t->ok($list2);
$t->is(get_class($list2), 'List_RubyLike');
$t->is($list2->length(), 3);
$t->is(LR(1, 2, 3)->length(), 3);
/* TODO
   - each()
   - each_index()
   - map()
   - grep()
   - find()
   - reduce()
 */
Exemple #4
0
<?php

require_once 'List/RubyLike.php';
echo LR(array("foo", "bar"))->push("baz", "piyo")->map(function ($v) {
    return strtoupper($v);
})->join(", ") . "\n";
echo LR(range(1, 5))->grep(function ($n) {
    return $n % 2 == 0;
})->map(function ($n) {
    return $n * $n;
})->sum() . "\n";