Esempio n. 1
0
 /**
  * Test the combination of intermediate and full set operators and their execution order
  */
 public function testScenario104()
 {
     $input = [1, 1, 10, 10, 2, 2, 9, 9, 15, 3, 3];
     $expected = [10, 1];
     $result = Psi::it($input)->anyMatch(function ($i) {
         return $i >= 15;
     })->map(function ($i) {
         return $i * 2;
     })->unique()->anyMatch(function ($i) {
         return $i >= 15;
     })->map(function ($i) {
         return $i / 2;
     })->rsort()->collect();
     $this->assertPsiCollectOutputMatches($expected, $result);
 }
Esempio n. 2
0
        return $this->val;
    }
}
/**  */
class PlayB extends PlayA
{
}
/**  */
class PlayC extends PlayB
{
}
$input = [0, "z", new \stdClass(), new PlayA(20), new PlayB(10), new PlayC(30)];
$result = Psi::it($input)->filter(new IsObject())->toArray();
var_dump($result);
$result = Psi::it($input)->filter(new IsNotObject())->toArray();
var_dump($result);
$result = Psi::it($input)->filter(new IsInstanceOf("PlayB"))->toArray();
var_dump($result);
$result = Psi::it($input)->filter(new IsNotInstanceOf("PlayB"))->toArray();
var_dump($result);
$result = Psi::it($input)->filter(new EqualTo("PlayB"))->toArray();
var_dump($result);
$result = Psi::it($input)->filter(new IsInstanceOf("PlayA"))->sortBy(function (PlayA $i) {
    return $i->getVal();
})->toArray();
var_dump("sortBy: ", $result);
$input = [0, 1, 2, 3];
$result = Psi::it($input)->filter(new GreaterThan(1))->toArray();
var_dump($result);
$result = Psi::it([0 => 'a', 1 => 'b', 2 => 'c', 'x', 'y', 'abz'], [0 => 'd', 1 => 'e', 2 => 'f'])->unique()->join(', ');
var_dump($result);
Esempio n. 3
0
 /**
  * @param array $input
  * @param int   $flags
  * @param array $expected
  *
  * @dataProvider provideTestSort
  */
 public function testSort($input, $flags, $expected)
 {
     $result = Psi::it($input)->sort($flags)->toArray();
     $this->assertEquals($expected, $result);
 }