Example #1
0
 public function testChain()
 {
     $duplicate = function ($n) {
         return [$n, $n];
     };
     $this->assertEquals([1, 1, 2, 2, 3, 3], P::toArray(P::chain($duplicate, [1, 2, 3])));
     $dup = P::chain($duplicate);
     $a = function () {
         (yield 1);
         (yield 2);
         (yield 3);
     };
     $this->assertEquals([1, 1, 2, 2, 3, 3], P::toArray($dup($a())));
     $b = [[1, 2], [3, 4], [5, 6]];
     $this->assertEquals([1, 2, 3, 4, 5, 6], P::toArray(P::chain('P::identity', $b)));
 }
Example #2
0
 public static function unnest($list)
 {
     Exception::assertList($list);
     return self::apply(P::chain('P::identity'), [$list]);
 }