Completed
Push — master ( 5e2d42...f80c85 )
by Amine
02:13
created
src/Stream.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      * @param  mixed $data
82 82
      * @return Stream
83 83
      */
84
-    public static function of ($data)
84
+    public static function of($data)
85 85
     {
86 86
         $data = func_get_args();
87 87
         if (count($data) == 1)
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
      * @param  array $operations
97 97
      * @return Stream
98 98
      */
99
-    protected static function with ($data, $operations, $type)
99
+    protected static function with($data, $operations, $type)
100 100
     {
101 101
         return new Stream($data, $operations, $type);
102 102
     }
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      * @param  array $operations
108 108
      * @return array|Error
109 109
      */
110
-    protected static function optimize ($operations)
110
+    protected static function optimize($operations)
111 111
     {
112 112
         // TODO: ...
113 113
         return $operations;
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
      * @param  mixed $data
121 121
      * @return mixed|Error
122 122
      */
123
-    protected static function execute ($operations, $data)
123
+    protected static function execute($operations, $data)
124 124
     {
125 125
         if (length($operations) == 0)
126 126
             return $data;
127
-        $operations = apply(_f('pipe'), map(function($operation){
127
+        $operations = apply(_f('pipe'), map(function($operation) {
128 128
             if ($operation['name'] == 'apply') {
129 129
                 return $operation['args'];
130 130
             }
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
      * @param  string $type
143 143
      * @return bool
144 144
      */
145
-    protected static function canApply ($operation, $type)
145
+    protected static function canApply($operation, $type)
146 146
     {
147 147
         return isset(Stream::$transformations[$operation]) && (
148 148
             $type == 'Unknown' ||
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      * @param  string $type
159 159
      * @return bool
160 160
      */
161
-    protected static function returnOf ($operation, $type)
161
+    protected static function returnOf($operation, $type)
162 162
     {
163 163
         return isset(Stream::$transformations[$operation][$type])
164 164
             ? Stream::$transformations[$operation][$type]
@@ -173,12 +173,12 @@  discard block
 block discarded – undo
173 173
      * @param  Stream $stream
174 174
      * @return Stream
175 175
      */
176
-    protected static function apply ($operation, $args, $stream)
176
+    protected static function apply($operation, $args, $stream)
177 177
     {
178 178
         if ($stream->type == 'Error') {
179 179
             return Stream::of(Error::of("Could not apply {$operation} to {$stream->type}", $stream->data));
180 180
         }
181
-        if (! Stream::canApply($operation, $stream->type)) {
181
+        if (!Stream::canApply($operation, $stream->type)) {
182 182
             $data = toString($stream->data);
183 183
             return Stream::of(Error::of("Could not apply {$operation} to {$stream->type}({$data})"));
184 184
         }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      *
195 195
      * @param mixed $data
196 196
      */
197
-    protected function __construct ($data, $operations, $type)
197
+    protected function __construct($data, $operations, $type)
198 198
     {
199 199
         $this->data = $data;
200 200
         $this->type = $type;
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
      * @signature Stream(a) -> a
233 233
      * @return mixed
234 234
      */
235
-    public function get ()
235
+    public function get()
236 236
     {
237 237
         if ($this->type == 'Error')
238 238
             return $this->data;
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
      * @param  callable $fn
252 252
      * @return Stream
253 253
      */
254
-    public function map (callable $fn)
254
+    public function map(callable $fn)
255 255
     {
256 256
         return Stream::apply('map', [$fn], $this);
257 257
     }
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      * @param  callable $predicate
269 269
      * @return Stream
270 270
      */
271
-    public function filter (callable $predicate)
271
+    public function filter(callable $predicate)
272 272
     {
273 273
         return Stream::apply('filter', [$predicate], $this);
274 274
     }
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
      * @param mixed $initial
287 287
      * @return Stream
288 288
      */
289
-    public function reduce ($fn, $initial)
289
+    public function reduce($fn, $initial)
290 290
     {
291 291
         return Stream::apply('reduce', [$fn, $initial], $this);
292 292
     }
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
      * @param callable $fn
306 306
      * @return Stream
307 307
      */
308
-    public function chain ($fn)
308
+    public function chain($fn)
309 309
     {
310 310
         return Stream::apply('chain', [$fn], $this);
311 311
     }
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
      * @signature Stream(String) -> Number
326 326
      * @return Stream
327 327
      */
328
-    public function length ()
328
+    public function length()
329 329
     {
330 330
         return Stream::apply('length', [], $this);
331 331
     }
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
      * @param int $number
347 347
      * @return Stream
348 348
      */
349
-    public function take ($number)
349
+    public function take($number)
350 350
     {
351 351
         return Stream::apply('take', [$number], $this);
352 352
     }
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
      * @param callable $fn
368 368
      * @return Stream
369 369
      */
370
-    public function then ($fn)
370
+    public function then($fn)
371 371
     {
372 372
         $result = $this;
373 373
         foreach (func_get_args() as $fn) {
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
      * @param  mixed|null $args...
418 418
      * @return Stream
419 419
      */
420
-    public function call ($method)
420
+    public function call($method)
421 421
     {
422 422
         $args = tail(func_get_args());
423 423
         return Stream::apply('apply', function($data) use($method, $args) {
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
      * @param  mixed|null $args...
472 472
      * @return Stream
473 473
      */
474
-    public function run ($method)
474
+    public function run($method)
475 475
     {
476 476
         $args = tail(func_get_args());
477 477
         return Stream::apply('apply', function($data) use($method, $args) {
Please login to merge, or discard this patch.
src/list.php 1 patch
Spacing   +17 added lines, -18 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
  * @return array
57 57
  */
58 58
 function filter() {
59
-    $filter = function($fn, $list){
59
+    $filter = function($fn, $list) {
60 60
         return array_values(array_filter($list, $fn));
61 61
     };
62 62
     return apply(curry($filter), func_get_args());
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
  * @return array
79 79
  */
80 80
 function reduce() {
81
-    $reduce = function($fn, $initial, $list){
81
+    $reduce = function($fn, $initial, $list) {
82 82
         return array_reduce($list, $fn, $initial);
83 83
     };
84 84
     return apply(curry($reduce), func_get_args());
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
  * @return array
105 105
  */
106 106
 function each() {
107
-    $each = function($fn, $list){
107
+    $each = function($fn, $list) {
108 108
         foreach ($list as $item) {
109 109
             apply($fn, [$item]);
110 110
         }
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
  * @return mixed
129 129
  */
130 130
 function head($list) {
131
-    if(is_string($list))
131
+    if (is_string($list))
132 132
         return substr($list, 0, 1);
133 133
     return (count($list) > 0)
134 134
         ? $list[0]
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
  * @return mixed
151 151
  */
152 152
 function last($list) {
153
-    if(is_string($list))
153
+    if (is_string($list))
154 154
         return substr($list, -1);
155 155
     return (count($list) > 0)
156 156
         ? $list[count($list) - 1]
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
  * @return array
174 174
  */
175 175
 function init($list) {
176
-    if(is_string($list))
176
+    if (is_string($list))
177 177
         return (strlen($list) > 1)
178 178
             ? substr($list, 0, strlen($list) - 1)
179 179
             : '';
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
  * @return array
199 199
  */
200 200
 function tail($list) {
201
-    if(is_string($list))
201
+    if (is_string($list))
202 202
         return (strlen($list) > 1)
203 203
             ? substr($list, 1)
204 204
             : '';
@@ -322,8 +322,7 @@  discard block
 block discarded – undo
322 322
  */
323 323
 function concatAll() {
324 324
     $concatAll = function($lists) {
325
-        return length($lists) == 0 ? [] :
326
-            reduce(concat(), head($lists), tail($lists));
325
+        return length($lists) == 0 ? [] : reduce(concat(), head($lists), tail($lists));
327 326
     };
328 327
     return apply(curry($concatAll), func_get_args());
329 328
 }
@@ -402,7 +401,7 @@  discard block
 block discarded – undo
402 401
  * @return array
403 402
  */
404 403
 function append() {
405
-    $append = function ($item, $list) {
404
+    $append = function($item, $list) {
406 405
         return insert(length($list), $item, $list);
407 406
     };
408 407
     return apply(curry($append), func_get_args());
@@ -449,7 +448,7 @@  discard block
 block discarded – undo
449 448
         $length = length($list);
450 449
         if ($count > $length || $count < -$length)
451 450
             return [];
452
-        if(is_string($list)) {
451
+        if (is_string($list)) {
453 452
             return ($count >= 0)
454 453
                 ? substr($list, 0, $count)
455 454
                 : substr($list, $count);
@@ -705,9 +704,9 @@  discard block
 block discarded – undo
705 704
  */
706 705
 function slices() {
707 706
     $slices = function($size, $list) {
708
-        if(empty($list))
707
+        if (empty($list))
709 708
             return is_string($list) ? '' : [];
710
-        if(length($list) <= $size)
709
+        if (length($list) <= $size)
711 710
             return [$list];
712 711
         return prepend(take($size, $list), slices($size, remove($size, $list)));
713 712
     };
@@ -731,7 +730,7 @@  discard block
 block discarded – undo
731 730
  */
732 731
 function contains() {
733 732
     $contains = function($item, $list) {
734
-        return -1 != indexOf($item, $list);
733
+        return - 1 != indexOf($item, $list);
735 734
     };
736 735
     return apply(curry($contains), func_get_args());
737 736
 }
@@ -780,7 +779,7 @@  discard block
 block discarded – undo
780 779
 function findLastIndex() {
781 780
     $findLastIndex = function($predicate, $list) {
782 781
         foreach (reverse(toPairs($list)) as $pair) {
783
-            if($predicate($pair[1]))
782
+            if ($predicate($pair[1]))
784 783
                 return $pair[0];
785 784
         }
786 785
         return null;
@@ -857,7 +856,7 @@  discard block
 block discarded – undo
857 856
             $index = findIndex(equals($item), $list);
858 857
         }
859 858
         return (false === $index || null === $index)
860
-            ? -1
859
+            ? - 1
861 860
             : $index;
862 861
     };
863 862
     return apply(curry($indexOf), func_get_args());
@@ -887,7 +886,7 @@  discard block
 block discarded – undo
887 886
             $index = findLastIndex(equals($item), $list);
888 887
         }
889 888
         return (false === $index || null === $index)
890
-            ? -1
889
+            ? - 1
891 890
             : $index;
892 891
     };
893 892
     return apply(curry($lastIndexOf), func_get_args());
@@ -972,7 +971,7 @@  discard block
 block discarded – undo
972 971
     $groupBy = function($fn, $list) {
973 972
         return reduce(function($result, $item) use($fn) {
974 973
             $index = $fn($item);
975
-            if (! isset($result[$index]))
974
+            if (!isset($result[$index]))
976 975
                 $result[$index] = [];
977 976
             $result[$index][] = $item;
978 977
             return $result;
Please login to merge, or discard this patch.