Ejemplo n.º 1
0
 public function testIntersectExpect()
 {
     $test1 = array(array("a" => "foo", "b" => "bar", "c" => "foobar"), array("a" => "foo", "b" => "bar", "c" => "barfoo"));
     $test2 = array(array("a" => "foo", "b" => "bar", "c" => "foobar"), array("a" => "helloworld", "b" => "bar", "c" => "barfoo"));
     $expectedin = array(array("a" => "foo", "b" => "bar", "c" => "foobar"));
     $expectedex = array(array("a" => "foo", "b" => "bar", "c" => "barfoo"), array("a" => "helloworld", "b" => "bar", "c" => "barfoo"));
     $list1 = \PerrysLambda\ArrayList::asObjectArray($test1);
     $list2 = \PerrysLambda\ArrayList::asObjectArray($test2);
     $this->assertEquals($expectedin, $list1->intersect($list2)->serialize());
     $this->assertEquals($expectedex, $list1->except($list2)->serialize());
 }
Ejemplo n.º 2
0
// Basic example
$watch->start();
$test = new AL(array(1, 2, 3, 4, 5, 6, 7, 8, 9));
L::vdl($test->where(function ($v) {
    return $v > 5;
})->toArray());
L::line("Select values greater than X from simple array", $watch->stop()->result());
echo "\n";
// Parse JSON (testdata)
L::line("Filesize of JSON is", number_format(filesize(__DIR__ . "/testdata.json") / 1024, 2), "KB");
$watch->start();
$data = json_decode(file_get_contents(__DIR__ . "/testdata.json"), true);
L::line("Loaded data from JSON file.", $watch->stop()->result(), ",", count($data), "records");
// Load JSON data into lambda
$watch->start();
$collection = AL::asObjectArray($data);
// ArrayList<ObjectArray>
L::line("Data imported into Lambda.", $watch->stop()->result(), ",", $collection->length(), "records");
// Unset JSON Data
unset($data);
L::line("Unset original JSON data.");
// where
$watch->start();
$subc = $collection->where(function (OA $r) {
    return $r->username == "userfoo";
});
L::line("Where user is userfoo.", $watch->stop()->result(), ",", $subc->length(), "records");
// groupby
$watch->start();
$grouped = $collection->groupBy(function (OA $r) {
    return $r->username;