コード例 #1
0
ファイル: Chain.php プロジェクト: wemash/hooray
 static function add($name, $method)
 {
     Chain::$links[$name] = function () use($method) {
         return hooray(call_user_func_array($method, func_get_args()));
     };
 }
コード例 #2
0
ファイル: flatmap.php プロジェクト: wemash/hooray
<?php

Chain::add('flatmap', function ($data, $action) {
    return hooray($data)->reduce(function ($carry, $datum) use($action) {
        $result = $action($datum);
        if (!is_array($result)) {
            $result = [$result];
        }
        return array_merge($carry, $result);
    }, []);
});
コード例 #3
0
ファイル: splice.test.php プロジェクト: wemash/hooray
 function testSplice()
 {
     $this->assertEquals([1, 2, 3], hooray(1, 4, 3)->splice(1, 1, 2)->realize());
 }
コード例 #4
0
ファイル: chunk.test.php プロジェクト: wemash/hooray
 function testChunkAcceptsPreserveKeys()
 {
     $this->assertEquals([['asdf' => 1], ['qwerty' => 2]], hooray(['asdf' => 1, 'qwerty' => 2])->chunk(1, true)->realize());
 }
コード例 #5
0
ファイル: take.test.php プロジェクト: wemash/hooray
 function testTake()
 {
     $this->assertEquals(['asdf', 'asdf'], hooray('asdf', 'asdf', 'qwerty')->take(2)->realize());
 }
コード例 #6
0
ファイル: growKeys.test.php プロジェクト: wemash/hooray
 function testGrowKeys()
 {
     $this->assertEquals(['ASDF' => 1], hooray(['asdf' => 1])->growKeys()->realize());
 }
コード例 #7
0
ファイル: pad.test.php プロジェクト: wemash/hooray
 function testPad()
 {
     $this->assertEquals([1, 1, 1, 1, 1], hooray(1)->pad(5, 1)->realize());
 }
コード例 #8
0
ファイル: unshift.test.php プロジェクト: wemash/hooray
 function testUnshift()
 {
     $this->assertEquals(['asdf', 'asdf'], hooray('asdf')->unshift('asdf')->realize());
 }
コード例 #9
0
ファイル: asEnglish.test.php プロジェクト: wemash/hooray
 function testSkipsOxfordCommaWhenOnlyGivenTwoItems()
 {
     $this->assertEquals('1 and 2', hooray(1, 2)->asEnglish());
 }
コード例 #10
0
ファイル: filter.test.php プロジェクト: wemash/hooray
 function testFilter()
 {
     $this->assertEquals([1, 2], hooray(1, 2, 3)->filter(function ($item) {
         return $item < 3;
     })->realize());
 }
コード例 #11
0
ファイル: shufflet.test.php プロジェクト: wemash/hooray
 function testShuffle()
 {
     $this->assertEquals([3, 1, 2], hooray(1, 2, 3)->shuffle(1000)->realize());
 }
コード例 #12
0
ファイル: sum.test.php プロジェクト: wemash/hooray
 function testSum()
 {
     $this->assertEquals(10, hooray(5, 5)->sum());
 }
コード例 #13
0
ファイル: reduce.test.php プロジェクト: wemash/hooray
 function testReduce()
 {
     $this->assertEquals(6, hooray(1, 2, 3)->reduce(function ($carry, $item) {
         return $carry + $item;
     }));
 }
コード例 #14
0
ファイル: asEnglish.php プロジェクト: wemash/hooray
<?php

Chain::addTerminal('asEnglish', function ($data, $ifEmpty = '') {
    return count($data) == 2 ? hooray($data)->join(' and ') : hooray($data)->join(', ', ', and ', $ifEmpty);
});
コード例 #15
0
ファイル: first.test.php プロジェクト: wemash/hooray
 function testWorksOnAssociativeArrays()
 {
     $this->assertEquals(1, hooray(["a" => 1, "b" => 2, "c" => 3])->first());
 }
コード例 #16
0
ファイル: countValues.test.php プロジェクト: wemash/hooray
 function testCountValues()
 {
     $this->assertEquals(['asdf' => 2, 'qwerty' => 1], hooray('asdf', 'asdf', 'qwerty')->countValues()->realize());
 }
コード例 #17
0
ファイル: drop.test.php プロジェクト: wemash/hooray
 function testDrop()
 {
     $this->assertEquals(['qwerty'], hooray('asdf', 'asdf', 'qwerty')->drop(2)->realize());
 }
コード例 #18
0
ファイル: flatmap.test.php プロジェクト: wemash/hooray
 function testFlatmapWithoutArrays()
 {
     $this->assertEquals([1, 2, 3], hooray(1, 2, 3)->flatmap(function ($item) {
         return $item;
     })->realize());
 }
コード例 #19
0
ファイル: shrinkKeys.test.php プロジェクト: wemash/hooray
 function testShrinkKeys()
 {
     $this->assertEquals(['asdf' => 1], hooray(['ASDF' => 1])->shrinkKeys()->realize());
 }
コード例 #20
0
ファイル: values.test.php プロジェクト: wemash/hooray
 function testValues()
 {
     $this->assertEquals([1, 2, 3], hooray(['asdf' => 1, 'qwerty' => 2, 'hjkl' => 3])->values()->realize());
 }
コード例 #21
0
ファイル: push.test.php プロジェクト: wemash/hooray
 function testPush()
 {
     $this->assertEquals([1, 2], hooray(1)->push(2)->realize());
 }
コード例 #22
0
ファイル: shift.test.php プロジェクト: wemash/hooray
 function testShift()
 {
     $this->assertEquals(1, hooray(1, 2, 3)->shift());
 }
コード例 #23
0
ファイル: join.test.php プロジェクト: wemash/hooray
 function testIfEmpty()
 {
     $this->assertEquals('nope', hooray()->join('', '', 'nope'));
 }
コード例 #24
0
ファイル: unique.php プロジェクト: wemash/hooray
<?php

Chain::add('unique', function ($data) {
    return hooray(array_unique($data, SORT_REGULAR))->values()->realize();
});
コード例 #25
0
ファイル: map.test.php プロジェクト: wemash/hooray
 function testMap()
 {
     $this->assertEquals([2, 3, 4], hooray(1, 2, 3)->map(function ($item) {
         return $item + 1;
     })->realize());
 }
コード例 #26
0
ファイル: Hooray.test.php プロジェクト: wemash/hooray
 function testAcceptsNonArrayArgument()
 {
     $this->assertEquals([1], hooray(1)->realize());
 }
コード例 #27
0
ファイル: keys.test.php プロジェクト: wemash/hooray
 function testKeys()
 {
     $this->assertEquals(['asdf', 'qwerty'], hooray(['asdf' => 1, 'qwerty' => 2])->keys()->realize());
 }
コード例 #28
0
ファイル: unique.test.php プロジェクト: wemash/hooray
 function testUnique()
 {
     $this->assertEquals(["asdf", "qwerty"], hooray("asdf", "asdf", "qwerty")->unique()->realize());
 }
コード例 #29
0
ファイル: column.test.php プロジェクト: wemash/hooray
 function testColumn()
 {
     $this->assertEquals([1, 2, 3], hooray([['a' => 1], ['a' => 2], ['a' => 3]])->column('a')->realize());
 }
コード例 #30
0
ファイル: pop.test.php プロジェクト: wemash/hooray
 function testPop()
 {
     $this->assertEquals(1, hooray(3, 2, 1)->pop());
 }