Completed
Pull Request — master (#2)
by Amine
01:50
created

list.php ➔ sort()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php namespace Tarsana\Functional;
2
/**
3
 * Useful functions to handle lists (arrays having only numeric keys).
4
 * @file
5
 */
6
7
/**
8
 * Curried version of `array_map`.
9
 *
10
 * ```php
11
 * $doubles = F\map(function($x) { return 2 * $x; });
12
 * $doubles([1, 2, 3, 4]); //=> [2, 4, 6, 8]
13
 * ```
14
 *
15
 * @stream
16
 * @signature (a -> b) -> [a] -> [b]
17
 * @param  callable $fn
0 ignored issues
show
Bug introduced by
There is no parameter named $fn. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
18
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
19
 * @return array
20
 */
21
function map() {
22
    static $map = false;
23
    $map = $map ?: curry(function($fn, $list) {
24
        return array_map($fn, $list);
25
    });
26
    return _apply($map, func_get_args());
27
}
28
29
/**
30
 * Applies a function to items of the array and concatenates the results.
31
 *
32
 * This is also known as `flatMap` in some libraries.
33
 * ```php
34
 * $words = F\chain(F\split(' '));
35
 * $words(['Hello World', 'How are you']); //=> ['Hello', 'World', 'How', 'are', 'you']
36
 * ```
37
 *
38
 * @stream
39
 * @signature (a -> [b]) -> [a] -> [b]
40
 * @param  callable $fn
0 ignored issues
show
Bug introduced by
There is no parameter named $fn. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
41
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
42
 * @return array
43
 */
44
function chain() {
45
    static $chain = false;
46
    $chain = $chain ?: curry(function($fn, $list) {
47
        return concatAll(map($fn, $list));
48
    });
49
    return _apply($chain, func_get_args());
50
}
51
52
/**
53
 * Curried version of `array_filter` with modified order of arguments.
54
 *
55
 * The callback is the first argument then the list.
56
 * ```php
57
 * $list = [1, 'aa', 3, [4, 5]];
58
 * $numeric = F\filter('is_numeric');
59
 * $numeric($list); //=> [1, 3]
60
 * ```
61
 * @stream
62
 * @signature (a -> Boolean) -> [a] -> [a]
63
 * @param  callable $fn
0 ignored issues
show
Bug introduced by
There is no parameter named $fn. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
64
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
65
 * @return array
66
 */
67
function filter() {
68
    static $filter = false;
69
    $filter = $filter ?: curry(function($fn, $list){
70
        return array_values(array_filter($list, $fn));
71
    });
72
    return _apply($filter, func_get_args());
73
}
74
75
/**
76
 * Curried version of `array_reduce` with modified order of
77
 * arguments ($callback, $initial, $list).
78
 *
79
 * ```php
80
 * $list = [1, 2, 3, 4];
81
 * $sum = F\reduce('Tarsana\Functional\plus', 0);
82
 * $sum($list); //=> 10
83
 * ```
84
 *
85
 * @stream
86
 * @signature (* -> a -> *) -> * -> [a] -> *
87
 * @param  callable $fn
0 ignored issues
show
Bug introduced by
There is no parameter named $fn. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
88
 * @param  mixed $initial
0 ignored issues
show
Bug introduced by
There is no parameter named $initial. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
89
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
90
 * @return array
91
 */
92 View Code Duplication
function reduce() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
    static $reduce = false;
94
    $reduce = $reduce ?: curry(function($fn, $initial, $list){
95
        return array_reduce($list, $fn, $initial);
96
    });
97
    return _apply($reduce, func_get_args());
98
}
99
100
/**
101
 * Applies the callback to each item and returns the original list.
102
 *
103
 * ```php
104
 * $list = [1, 2, 3, 4];
105
 * $s = 0;
106
 * F\each(function($item) use(&$s){
107
 *     $s += $item;
108
 * }, $list);
109
 *
110
 * $s; //=> 10
111
 * ```
112
 *
113
 * @stream
114
 * @signature (a -> *) -> [a] -> [a]
115
 * @param  callable $fn
0 ignored issues
show
Bug introduced by
There is no parameter named $fn. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
116
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
117
 * @return array
118
 */
119 View Code Duplication
function each() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
120
    static $each = false;
121
    $each = $each ?: curry(function($fn, $list){
122
        foreach ($list as $item) {
123
            apply($fn, [$item]);
124
        }
125
        return $list;
126
    });
127
    return _apply($each, func_get_args());
128
}
129
130
/**
131
 * Returns the first item of the given array or string.
132
 *
133
 * ```php
134
 * F\head([1, 2, 3, 4]); //=> 1
135
 * F\head('Hello'); //=> 'H'
136
 * F\head([]); //=> null
137
 * F\head(''); //=> ''
138
 * ```
139
 *
140
 * @stream
141
 * @signature [a] -> a
142
 * @signature String -> String
143
 * @param  array|string $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
144
 * @return mixed
145
 */
146 View Code Duplication
function head() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
147
    static $head = false;
148
    $head = $head ?: curry(function($list) {
149
        if(is_string($list))
150
            return substr($list, 0, 1);
151
        return (count($list) > 0)
152
            ? $list[0]
153
            : null;
154
    });
155
    return _apply($head, func_get_args());
156
}
157
158
/**
159
 * Returns the last item of the given array or string.
160
 *
161
 * ```php
162
 * F\last([1, 2, 3, 4]); //=> 4
163
 * F\last('Hello'); //=> 'o'
164
 * F\last([]); //=> null
165
 * F\last(''); //=> ''
166
 * ```
167
 *
168
 * @stream
169
 * @signature [a] -> a
170
 * @signature String -> String
171
 * @param  array|string $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
172
 * @return mixed
173
 */
174 View Code Duplication
function last () {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
175
    static $last = false;
176
    $last = $last ?: curry(function($list) {
177
        if(is_string($list))
178
            return substr($list, -1);
179
        return (count($list) > 0)
180
            ? $list[count($list) - 1]
181
            : null;
182
    });
183
    return _apply($last, func_get_args());
184
}
185
186
/**
187
 * Returns all but the last element of the given array or string.
188
 *
189
 * ```php
190
 * F\init([1, 2, 3, 4]); //=> [1, 2, 3]
191
 * F\init('Hello'); //=> 'Hell'
192
 * F\init([7]); //=> []
193
 * F\init([]); //=> []
194
 * F\init(''); //=> ''
195
 * ```
196
 *
197
 * @stream
198
 * @signature [a] -> a
199
 * @signature String -> String
200
 * @param  array|string $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
201
 * @return array
202
 */
203
function init () {
204
    static $init = false;
205
    $init = $init ?: curry(function($list) {
206 View Code Duplication
        if(is_string($list))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
207
            return (strlen($list) > 1)
208
                ? substr($list, 0, strlen($list) - 1)
209
                : '';
210
        return (count($list) > 1)
211
            ? array_slice($list, 0, count($list) - 1)
212
            : [];
213
    });
214
    return _apply($init, func_get_args());
215
}
216
217
/**
218
 * Returns all but the first element of the given array or string.
219
 *
220
 * ```php
221
 * F\tail([1, 2, 3, 4]); //=> [2, 3, 4]
222
 * F\tail('Hello'); //=> 'ello'
223
 * F\tail([7]); //=> []
224
 * F\tail([]); //=> []
225
 * F\tail(''); //=> ''
226
 * ```
227
 *
228
 * @stream
229
 * @signature [a] -> a
230
 * @signature String -> String
231
 * @param  array|string $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
232
 * @return array
233
 */
234
function tail () {
235
    static $tail = false;
236
    $tail = $tail ?: curry(function($list) {
237 View Code Duplication
        if(is_string($list))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
238
            return (strlen($list) > 1)
239
                ? substr($list, 1)
240
                : '';
241
        return (count($list) > 1)
242
            ? array_slice($list, 1)
243
            : [];
244
    });
245
    return _apply($tail, func_get_args());
246
}
247
248
/**
249
 * Alias of `array_reverse()` and `strrev()`.
250
 *
251
 * ```php
252
 * F\reverse([1, 2, 3, 4]); //=> [4, 3, 2, 1]
253
 * F\reverse('Hello'); //=> 'olleH'
254
 * ```
255
 *
256
 * @stream
257
 * @signature [a] -> [a]
258
 * @signature String -> String
259
 * @param  array|string $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
260
 * @return array
261
 */
262 View Code Duplication
function reverse () {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
263
    static $reverse = false;
264
    $reverse = $reverse ?: curry(function($list) {
265
        return is_string($list)
266
            ? strrev($list)
267
            : array_reverse($list);
268
    });
269
    return _apply($reverse, func_get_args());
270
}
271
272
/**
273
 * Alias for `count()` and `strlen()`.
274
 *
275
 * ```php
276
 * F\length([1, 2, 3, 4]); //=> 4
277
 * F\length('Hello'); //=> 5
278
 * ```
279
 *
280
 * @stream
281
 * @signature [a] -> Number
282
 * @signature String -> Number
283
 * @param  array|string $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
284
 * @return int
285
 */
286 View Code Duplication
function length() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
287
    static $length = false;
288
    $length = $length ?: curry(function($list) {
289
        return is_string($list)
290
            ? strlen($list)
291
            : count($list);
292
    });
293
    return _apply($length, func_get_args());
294
}
295
296
/**
297
 * Checks if the `$predicate` is verified by **all** items of the array.
298
 *
299
 * ```php
300
 * $allNotNull = F\allSatisfies(F\pipe(F\eq(0), F\not()));
301
 * $allNotNull([9, 3, 2, 4]); //=> true
302
 * $allNotNull([9, 3, 0, 4]); //=> false
303
 * ```
304
 *
305
 * @stream
306
 * @signature (a -> Boolean) -> [a] -> Boolean
307
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
308
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
309
 * @return bool
310
 */
311 View Code Duplication
function allSatisfies() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
312
    static $allSatisfies = false;
313
    $allSatisfies = $allSatisfies ?: curry(function($predicate, $list) {
314
        return length(filter($predicate, $list)) == length($list);
315
    });
316
    return _apply($allSatisfies, func_get_args());
317
}
318
319
/**
320
 * Checks if the `$predicate` is verified by **any** item of the array.
321
 *
322
 * ```php
323
 * $anyNumeric = F\anySatisfies('is_numeric');
324
 * $anyNumeric(['Hello', '12', []]); //=> true
325
 * $anyNumeric(['Hello', 'Foo']); //=> false
326
 * ```
327
 *
328
 * @stream
329
 * @signature (a -> Boolean) -> [a] -> Boolean
330
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
331
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
332
 * @return bool
333
 */
334
function anySatisfies() {
335
    static $anySatisfies = false;
336
    $anySatisfies = $anySatisfies ?: curry(function($predicate, $list) {
337
        return null != findIndex($predicate, $list);
338
    });
339
    return _apply($anySatisfies, func_get_args());
340
}
341
342
/**
343
 * Concatenates two arrays or strings.
344
 *
345
 * ```php
346
 * F\concat([1, 2], [3, 4]); //=> [1, 2, 3, 4]
347
 * F\concat('Hello ', 'World'); //=> 'Hello World'
348
 * ```
349
 *
350
 * @stream
351
 * @signature [*] -> [*] -> [*]
352
 * @signature String -> String -> String
353
 * @param  array $list1
0 ignored issues
show
Bug introduced by
There is no parameter named $list1. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
354
 * @param  array $list2
0 ignored issues
show
Bug introduced by
There is no parameter named $list2. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
355
 * @return array
356
 */
357
function concat() {
358
    static $concat = false;
359
    $concat = $concat ?: curry(function($list1, $list2) {
360
        $t1 = toString($list1);
0 ignored issues
show
Unused Code introduced by
$t1 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
361
        $t2 = toString($list2);
0 ignored issues
show
Unused Code introduced by
$t2 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
362
        if (is_string($list1) && is_string($list2))
363
            return $list1 . $list2;
364
        return array_merge($list1, $list2);
365
    });
366
    return _apply($concat, func_get_args());
367
}
368
369
/**
370
 * Concatenates a list of arrays or strings.
371
 *
372
 * ```php
373
 * F\concatAll([[1, 2], [3, 4], [5, 6]]); //=> [1, 2, 3, 4, 5, 6]
374
 * F\concatAll(['Hello ', 'World', ' !']); //=> 'Hello World !'
375
 * ```
376
 *
377
 * @stream
378
 * @signature [[a]] -> [a]
379
 * @param  array $lists
0 ignored issues
show
Bug introduced by
There is no parameter named $lists. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
380
 * @return array
381
 */
382
function concatAll() {
383
    static $concatAll = false;
384
    $concatAll = $concatAll ?: curry(function($lists) {
385
        return length($lists) == 0 ? [] :
386
            reduce(concat(), head($lists), tail($lists));
387
    });
388
    return _apply($concatAll, func_get_args());
389
}
390
391
/**
392
 * Inserts an item at some position into an array or a substring into a string.
393
 *
394
 * If `$position < 0` the item or substring is inserted before the last `|$position|` elements/characters.
395
 * ```php
396
 * F\insert(2, 'x', [1, 2, 3, 4]); //=> [1, 2, 'x', 3, 4]
397
 * F\insert(-1,  'x', [1, 2, 3, 4]); //=> [1, 2, 3, 'x', 4]
398
 * F\insert(11, 'x', [1, 2, 3, 4]); //=> [1, 2, 3, 4, 'x']
399
 * F\insert(0, 'x', [1, 2, 3, 4]); //=> ['x', 1, 2, 3, 4]
400
 * F\insert(-11, 'x', [1, 2, 3, 4]); //=> ['x', 1, 2, 3, 4]
401
 * F\insert(3, 'l', 'Helo World'); //=> 'Hello World'
402
 * ```
403
 *
404
 * @stream
405
 * @signature Number -> a -> [a] -> [a]
406
 * @signature Number -> String -> String -> String
407
 * @param  int $position
0 ignored issues
show
Bug introduced by
There is no parameter named $position. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
408
 * @param  mixed $item
0 ignored issues
show
Bug introduced by
There is no parameter named $item. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
409
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
410
 * @return array
411
 */
412 View Code Duplication
function insert() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
413
    static $insert = false;
414
    $insert = $insert ?: curry(function($position, $item, $list) {
415
        return (is_string($list))
416
            ? insertAll($position, $item, $list)
417
            : insertAll($position, [$item], $list);
418
    });
419
    return _apply($insert, func_get_args());
420
}
421
422
/**
423
 * Same as `insert` but inserts an array instead of a single item.
424
 *
425
 * ```php
426
 * F\insertAll(2, ['x', 'y'], [1, 2, 3, 4]); //=> [1, 2, 'x', 'y', 3, 4]
427
 * F\insertAll(-1,  ['x', 'y'], [1, 2, 3, 4]); //=> [1, 2, 3, 'x', 'y', 4]
428
 * F\insertAll(11, ['x', 'y'], [1, 2, 3, 4]); //=> [1, 2, 3, 4, 'x', 'y']
429
 * F\insertAll(0, ['x', 'y'], [1, 2, 3, 4]); //=> ['x', 'y', 1, 2, 3, 4]
430
 * F\insertAll(-11, ['x', 'y'], [1, 2, 3, 4]); //=> ['x', 'y', 1, 2, 3, 4]
431
 * F\insertAll(2, 'llo', 'He World'); //=> 'Hello World'
432
 * ```
433
 *
434
 * @stream
435
 * @signature Number -> [a] -> [a] -> [a]
436
 * @signature Number -> String -> String -> String
437
 * @param  int $position
0 ignored issues
show
Bug introduced by
There is no parameter named $position. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
438
 * @param  mixed $items
0 ignored issues
show
Bug introduced by
There is no parameter named $items. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
439
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
440
 * @return array
441
 */
442
function insertAll() {
443
    static $insertAll = false;
444
    $insertAll = $insertAll ?: curry(function($position, $items, $list) {
445
        $length = length($list);
446
        if ($position < 0)
447
            $position = $length + $position;
448
        if ($position < 0)
449
            $position = 0;
450
        return ($position >= $length)
451
            ? concat($list, $items)
452
            : concatAll([take($position, $list), $items, remove($position, $list)]);
453
    });
454
    return _apply($insertAll, func_get_args());
455
}
456
457
/**
458
 * Appends an item to an array or a substring to a string.
459
 *
460
 * ```php
461
 * F\append(5, [1, 2, 3]); //=> [1, 2, 3, 5]
462
 * F\append(' World', 'Hello'); //=> 'Hello World'
463
 * ```
464
 *
465
 * @stream
466
 * @signature * -> [*] -> [*]
467
 * @signature String -> String -> String
468
 * @param  mixed $item
0 ignored issues
show
Bug introduced by
There is no parameter named $item. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
469
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
470
 * @return array
471
 */
472 View Code Duplication
function append() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
473
    static $append = false;
474
    $append = $append ?: curry(function ($item, $list) {
475
        return insert(length($list), $item, $list);
476
    });
477
    return _apply($append, func_get_args());
478
}
479
480
/**
481
 * Inserts an item at the begining of an array or a substring at the begining of a string.
482
 *
483
 * Note that this function is equivalent to `insert(0)`.
484
 * ```php
485
 * F\prepend(5, [1, 2, 3]); //=> [5, 1, 2, 3]
486
 * F\prepend('Hello ', 'World'); //=> 'Hello World'
487
 * ```
488
 *
489
 * @stream
490
 * @signature a -> [a] -> [a]
491
 * @signature String -> String -> String
492
 * @param  mixed $item
0 ignored issues
show
Bug introduced by
There is no parameter named $item. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
493
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
494
 * @return array
495
 */
496
function prepend() {
497
    return _apply(insert(0), func_get_args());
498
}
499
500
/**
501
 * Takes a number of elements from an array.
502
 *
503
 * If `$count` is negative, the elements are taken from the end of the array.
504
 * ```php
505
 * $items = ['Foo', 'Bar', 'Baz'];
506
 * F\take(2, $items); //=> ['Foo', 'Bar']
507
 * F\take(0, $items); //=> []
508
 * F\take(-2, $items); //=> ['Bar', 'Baz']
509
 * F\take(5, 'Hello World'); //=> 'Hello'
510
 * F\take(-5, 'Hello World'); //=> 'World'
511
 * ```
512
 *
513
 * @stream
514
 * @signature Number -> [a] -> [a]
515
 * @signature Number -> String -> String
516
 * @param  int $count
0 ignored issues
show
Bug introduced by
There is no parameter named $count. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
517
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
518
 * @return array
519
 */
520
function take() {
521
    static $take = false;
522
    $take = $take ?: curry(function($count, $list) {
523
        $length = length($list);
524
        if ($count > $length || $count < -$length)
525
            return [];
526
        if(is_string($list)) {
527
            return ($count >= 0)
528
                ? substr($list, 0, $count)
529
                : substr($list, $count);
530
        }
531
        return ($count >= 0)
532
            ? array_slice($list, 0, $count)
533
            : array_slice($list, $count);
534
    });
535
    return _apply($take, func_get_args());
536
}
537
538
/**
539
 * Takes elements from an array while they match the given predicate.
540
 *
541
 * It stops at the first element not matching the predicate and does not include it in the result.
542
 * ```php
543
 * $items = ['Foo', 'Fun', 'Dev', 'Bar', 'Baz'];
544
 * F\takeWhile(F\startsWith('F'), $items); //=> ['Foo', 'Fun']
545
 * F\takeWhile(F\startsWith('D'), $items); //=> []
546
 * ```
547
 *
548
 * @stream
549
 * @signature (a -> Boolean) -> [a] -> [a]
550
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
551
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
552
 * @return array
553
 */
554 View Code Duplication
function takeWhile() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
555
    static $takeWhile = false;
556
    $takeWhile = $takeWhile ?: curry(function($predicate, $list) {
557
        $first = head($list);
558
        return (null == $first || !$predicate($first))
559
            ? []
560
            : prepend($first, takeWhile($predicate, tail($list)));
561
562
    });
563
    return _apply($takeWhile, func_get_args());
564
}
565
566
/**
567
 * Same as `takeWhile` but taking elements from the end of the array.
568
 *
569
 * ```php
570
 * $items = ['Foo', 'Fun', 'Dev', 'Bar', 'Baz'];
571
 * F\takeLastWhile(F\startsWith('B'), $items); //=> ['Bar', 'Baz']
572
 * F\takeLastWhile(F\startsWith('D'), $items); //=> []
573
 * ```
574
 *
575
 * @stream
576
 * @signature (a -> Boolean) -> [a] -> [a]
577
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
578
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
579
 * @return array
580
 */
581 View Code Duplication
function takeLastWhile() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
582
    static $takeLastWhile = false;
583
    $takeLastWhile = $takeLastWhile ?: curry(function($predicate, $list) {
584
        $last = last($list);
585
        return (null == $last || !$predicate($last))
586
            ? []
587
            : append($last, takeLastWhile($predicate, init($list)));
588
589
    });
590
    return _apply($takeLastWhile, func_get_args());
591
}
592
593
/**
594
 * Takes elements from an array **until** the predicate
595
 * is satisfied, not including the satisfying element.
596
 *
597
 * ```php
598
 * $items = ['Foo', 'Fun', 'Dev', 'Bar', 'Baz'];
599
 * F\takeUntil(F\startsWith('B'), $items); //=> ['Foo', 'Fun', 'Dev']
600
 * F\takeUntil(F\startsWith('F'), $items); //=> []
601
 * ```
602
 *
603
 * @stream
604
 * @signature (a -> Boolean) -> [a] -> [a]
605
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
606
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
607
 * @return array
608
 */
609
function takeUntil() {
610
    static $takeUntil = false;
611
    $takeUntil = $takeUntil ?: curry(function($predicate, $list) {
612
        return takeWhile(pipe($predicate, not()), $list);
613
    });
614
    return _apply($takeUntil, func_get_args());
615
}
616
617
/**
618
 * Same as `takeUntil` but takes elements from the end of the array.
619
 *
620
 * ```php
621
 * $items = ['Foo', 'Fun', 'Dev', 'Bar', 'Baz'];
622
 * F\takeLastUntil(F\startsWith('F'), $items); //=> ['Dev', 'Bar', 'Baz']
623
 * F\takeLastUntil(F\startsWith('B'), $items); //=> []
624
 * ```
625
 *
626
 * @stream
627
 * @signature (a -> Boolean) -> [a] -> [a]
628
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
629
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
630
 * @return array
631
 */
632
function takeLastUntil() {
633
    static $takeLastUntil = false;
634
    $takeLastUntil = $takeLastUntil ?: curry(function($predicate, $list) {
635
        return takeLastWhile(pipe($predicate, not()), $list);
636
    });
637
    return _apply($takeLastUntil, func_get_args());
638
}
639
640
/**
641
 * Removes a number of elements from an array.
642
 *
643
 * If `$count` is negative, the elements are
644
 * removed from the end of the array.
645
 * ```php
646
 * $items = ['Foo', 'Bar', 'Baz'];
647
 * F\remove(2, $items); //=> ['Baz']
648
 * F\remove(-1, $items); //=> ['Foo', 'Bar']
649
 * F\remove(5, $items); //=> []
650
 * F\remove(6, 'Hello World'); //=> 'World'
651
 * F\remove(-6, 'Hello World'); //=> 'Hello'
652
 * ```
653
 *
654
 * @stream
655
 * @signature Number -> [a] -> [a]
656
 * @signature Number -> String -> String
657
 * @param  int $count
0 ignored issues
show
Bug introduced by
There is no parameter named $count. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
658
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
659
 * @return array
660
 */
661
function remove() {
662
    static $remove = false;
663
    $remove = $remove ?: curry(function($count, $list) {
664
        $length = length($list);
665
        if ($count > $length || $count < -$length)
666
            return [];
667
        return ($count > 0)
668
            ? take($count - $length, $list)
669
            : take($count + $length, $list);
670
    });
671
    return _apply($remove, func_get_args());
672
}
673
674
/**
675
 * Removes elements from an array while they match the given predicate.
676
 *
677
 * It stops at the first element not matching the predicate and does not remove it.
678
 * ```php
679
 * $items = ['Foo', 'Fun', 'Dev', 'Bar', 'Baz'];
680
 * F\removeWhile(F\startsWith('F'), $items); //=> ['Dev', 'Bar', 'Baz']
681
 * F\removeWhile(F\startsWith('D'), $items); //=> ['Foo', 'Fun', 'Dev', 'Bar', 'Baz']
682
 * ```
683
 *
684
 * @stream
685
 * @signature (a -> Boolean) -> [a] -> [a]
686
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
687
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
688
 * @return array
689
 */
690 View Code Duplication
function removeWhile() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
691
    static $removeWhile = false;
692
    $removeWhile = $removeWhile ?: curry(function($predicate, $list) {
693
        return remove(length(takeWhile($predicate, $list)), $list);
694
    });
695
    return _apply($removeWhile, func_get_args());
696
}
697
698
/**
699
 * Same as `removeWhile` but removes elements from the end of the array.
700
 *
701
 * ```php
702
 * $items = ['Foo', 'Fun', 'Bye', 'Dev', 'Bar', 'Baz'];
703
 * F\removeLastWhile(F\startsWith('F'), $items); //=> ['Foo', 'Fun', 'Bye', 'Dev', 'Bar', 'Baz']
704
 * F\removeLastWhile(F\startsWith('B'), $items); //=> ['Foo', 'Fun', 'Bye', 'Dev']
705
 * ```
706
 *
707
 * @stream
708
 * @signature (a -> Boolean) -> [a] -> [a]
709
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
710
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
711
 * @return array
712
 */
713 View Code Duplication
function removeLastWhile() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
714
    static $removeLastWhile = false;
715
    $removeLastWhile = $removeLastWhile ?: curry(function($predicate, $list) {
716
        return remove(- length(takeLastWhile($predicate, $list)), $list);
717
    });
718
    return _apply($removeLastWhile, func_get_args());
719
}
720
721
/**
722
 * Removes elements from an array **until** the predicate
723
 * is satisfied, not removing the satisfying element.
724
 *
725
 * ```php
726
 * $items = ['Foo', 'Fun', 'Dev', 'Bar', 'Baz'];
727
 * F\removeUntil(F\startsWith('B'), $items); //=> ['Bar', 'Baz']
728
 * F\removeUntil(F\startsWith('F'), $items); //=> ['Foo', 'Fun', 'Dev', 'Bar', 'Baz']
729
 * F\removeUntil(F\startsWith('A'), $items); //=> []
730
 * ```
731
 *
732
 * @stream
733
 * @signature (a -> Boolean) -> [a] -> [a]
734
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
735
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
736
 * @return array
737
 */
738 View Code Duplication
function removeUntil() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
739
    static $removeUntil = false;
740
    $removeUntil = $removeUntil ?: curry(function($predicate, $list) {
741
        return remove(length(takeUntil($predicate, $list)), $list);
742
    });
743
    return _apply($removeUntil, func_get_args());
744
}
745
746
/**
747
 * Same as `removeUntil` but removes elements from the end of the array.
748
 *
749
 * ```php
750
 * $items = ['Foo', 'Fun', 'Dev', 'Bar', 'Baz'];
751
 * F\removeLastUntil(F\startsWith('B'), $items); //=> ['Foo', 'Fun', 'Dev', 'Bar', 'Baz']
752
 * F\removeLastUntil(F\startsWith('F'), $items); //=> ['Foo', 'Fun']
753
 * F\removeLastUntil(F\startsWith('A'), $items); //=> []
754
 * ```
755
 *
756
 * @stream
757
 * @signature (a -> Boolean) -> [a] -> [a]
758
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
759
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
760
 * @return array
761
 */
762 View Code Duplication
function removeLastUntil() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
763
    static $removeLastUntil = false;
764
    $removeLastUntil = $removeLastUntil ?: curry(function($predicate, $list) {
765
        return remove(- length(takeLastUntil($predicate, $list)), $list);
766
    });
767
    return _apply($removeLastUntil, func_get_args());
768
}
769
770
/**
771
 * Converts an array of (key, value) pairs to an object (instance of `stdClass`).
772
 *
773
 * ```php
774
 * F\fromPairs([['name', 'Foo'], ['age', 11]]); //=> (object) ['name' => 'Foo', 'age' => 11]
775
 * ```
776
 *
777
 * @stream
778
 * @signature [(k, v)] -> {k: v}
779
 * @param  array $pairs
0 ignored issues
show
Bug introduced by
There is no parameter named $pairs. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
780
 * @return stdClass
781
 */
782
function fromPairs() {
783
    static $fromPairs = false;
784
    $fromPairs = $fromPairs ?: curry(function($pairs) {
785
        return reduce(function($result, $pair) {
786
            $result->{$pair[0]} = $pair[1];
787
            return $result;
788
        }, new \stdClass, $pairs);
789
    });
790
    return _apply($fromPairs, func_get_args());
791
}
792
793
/**
794
 * Gets an array of slices of size `$size` from an array.
795
 *
796
 * ```php
797
 * $pairs = F\slices(2);
798
 * $pairs([1, 2, 3, 4, 5]); //=> [[1, 2], [3, 4], [5]]
799
 * $pairs("Hello World"); //=> ['He', 'll', 'o ', 'Wo', 'rl', 'd']
800
 * F\slices(5, [1, 2]); //=> [[1, 2]]
801
 * F\slices(3, []); //=> []
802
 * F\slices(3, ''); //=> ''
803
 * ```
804
 *
805
 * @stream
806
 * @signature Number -> [a] -> [[a]]
807
 * @signature Number -> String -> [String]
808
 * @param  int $size
0 ignored issues
show
Bug introduced by
There is no parameter named $size. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
809
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
810
 * @return array
811
 */
812
function slices() {
813
    static $slices = false;
814
    $slices = $slices ?: curry(function($size, $list) {
815
        if(empty($list))
816
            return is_string($list) ? '' : [];
817
        if(length($list) <= $size)
818
            return [$list];
819
        return prepend(take($size, $list), slices($size, remove($size, $list)));
820
    });
821
    return _apply($slices, func_get_args());
822
}
823
824
/**
825
 * Checks if an array contains an item.
826
 *
827
 * ```php
828
 * F\contains('foo', ['foo', 'bar', 'baz']); //=> true
829
 * F\contains('hi', ['foo', 'bar', 'baz']); //=> false
830
 * F\contains('hi', 'Hello World'); //=> false
831
 * F\contains('He', 'Hello World'); //=> true
832
 * ```
833
 *
834
 * @stream
835
 * @signature a -> [a] -> Boolean
836
 * @signature String -> String -> Boolean
837
 * @param  mixed $item
0 ignored issues
show
Bug introduced by
There is no parameter named $item. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
838
 * @param  array|string $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
839
 * @return bool
840
 */
841
function contains() {
842
    static $contains = false;
843
    $contains = $contains ?: curry(function($item, $list) {
844
        return -1 != indexOf($item, $list);
845
    });
846
    return _apply($contains, func_get_args());
847
}
848
849
/**
850
 * Returns the position/key of the first item satisfying the
851
 * predicate in the array or null if no such element is found.
852
 *
853
 * ```php
854
 * F\findIndex(F\startsWith('b'), ['foo', 'bar', 'baz']); //=> 1
855
 * F\findIndex(F\startsWith('b'), ['a' => 'foo', 'b' => 'bar', 'c' => 'baz']); //=> 'b'
856
 * F\findIndex(F\startsWith('c'), ['foo', 'bar', 'baz']); //=> null
857
 * ```
858
 *
859
 * @stream
860
 * @signature (a -> Boolean) -> [a] -> Maybe(Number)
861
 * @signature (v -> Boolean) -> {k: v} -> Maybe(k)
862
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
863
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
864
 * @return mixed
865
 */
866
function findIndex() {
867
    static $findIndex = false;
868
    $findIndex = $findIndex ?: curry(function($predicate, $list) {
869
        foreach ($list as $key => $value) {
870
            if ($predicate($value))
871
                return $key;
872
        }
873
        return null;
874
    });
875
    return _apply($findIndex, func_get_args());
876
}
877
878
/**
879
 * Returns the position/key of the last item satisfying the
880
 * predicate in the array or null if no such element is found.
881
 *
882
 * ```php
883
 * F\findLastIndex(F\startsWith('b'), ['foo', 'bar', 'baz']); //=> 2
884
 * F\findLastIndex(F\startsWith('b'), ['a' => 'foo', 'b' => 'bar', 'c' => 'baz']); //=> 'c'
885
 * F\findLastIndex(F\startsWith('c'), ['foo', 'bar', 'baz']); //=> null
886
 * ```
887
 *
888
 * @stream
889
 * @signature (a -> Boolean) -> [a] -> Maybe(Number)
890
 * @signature (v -> Boolean) -> {k: v} -> Maybe(k)
891
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
892
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
893
 * @return mixed
894
 */
895
function findLastIndex() {
896
    static $findLastIndex = false;
897
    $findLastIndex = $findLastIndex ?: curry(function($predicate, $list) {
898
        foreach (reverse(toPairs($list)) as $pair) {
899
            if($predicate($pair[1]))
900
                return $pair[0];
901
        }
902
        return null;
903
    });
904
    return _apply($findLastIndex, func_get_args());
905
}
906
907
/**
908
 * Returns the first item satisfying the predicate in
909
 * the array or null if no such element is found.
910
 *
911
 * ```php
912
 * F\find(F\startsWith('b'), ['foo', 'bar', 'baz']); //=> 'bar'
913
 * F\find(F\startsWith('c'), ['foo', 'bar', 'baz']); //=> null
914
 * ```
915
 *
916
 * @stream
917
 * @signature (a -> Boolean) -> [a] -> Maybe(a)
918
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
919
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
920
 * @return mixed
921
 */
922 View Code Duplication
function find() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
923
    static $find = false;
924
    $find = $find ?: curry(function($predicate, $list) {
925
        return get(findIndex($predicate, $list), $list);
926
    });
927
    return _apply($find, func_get_args());
928
}
929
930
/**
931
 * Returns the last item satisfying the predicate in
932
 * the array or null if no such element is found.
933
 *
934
 * ```php
935
 * F\findLast(F\startsWith('b'), ['foo', 'bar', 'baz']); //=> 'baz'
936
 * F\findLast(F\startsWith('c'), ['foo', 'bar', 'baz']); //=> null
937
 * ```
938
 *
939
 * @stream
940
 * @signature (a -> Boolean) -> [a] -> Maybe(a)
941
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
942
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
943
 * @return mixed
944
 */
945 View Code Duplication
function findLast() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
946
    static $findLast = false;
947
    $findLast = $findLast ?: curry(function($predicate, $list) {
948
        return get(findLastIndex($predicate, $list), $list);
949
    });
950
    return _apply($findLast, func_get_args());
951
}
952
953
/**
954
 * Returns the index of an item/substring in a list/string.
955
 *
956
 * If `$list` is an array, it returns the **key** of the first **item** which is equal to `$item`.
957
 * If `$list` is a string, it returns the **position** of the first **substring** which is equal to `$item`.
958
 * If `$list` is an object, it returns the **name** of the first **attribute** which is equal to `$item`.
959
 * If the searched item, substring or attribute is not found; `null` is returned.
960
 * Note that elements are deeply compared using `Tarsana\Functional\equals`.
961
 * ```php
962
 * F\indexOf(['Hello', 'World'], [1, ['Hello', 'World'], true, ['Hello', 'World']]); //=> 1
963
 * F\indexOf(['Hello'], [1, ['Hello', 'World'], true]); //=> -1
964
 * F\indexOf('World', 'Hello World'); //=> 6
965
 * F\indexOf('World !', 'Hello World'); //=> -1
966
 * F\indexOf('foo', (object) ['name' => 'foo', 'age' => 11]); //=> 'name'
967
 * ```
968
 *
969
 * @stream
970
 * @signature a -> [a] -> Number
971
 * @signature v -> {k: v} -> Maybe(k)
972
 * @signature String -> String -> Number
973
 * @param  mixed $item
0 ignored issues
show
Bug introduced by
There is no parameter named $item. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
974
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
975
 * @return int
976
 */
977 View Code Duplication
function indexOf() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
978
    static $indexOf = false;
979
    $indexOf = $indexOf ?: curry(function($item, $list) {
980
        if (is_string($list)) {
981
            $index = strpos($list, $item);
982
        } else {
983
            $index = findIndex(equals($item), $list);
984
        }
985
        return (false === $index || null === $index)
986
            ? -1
987
            : $index;
988
    });
989
    return _apply($indexOf, func_get_args());
990
}
991
992
/**
993
 * Same as `indexOf` but returns the key/position/name of the last item/substring/attribute.
994
 *
995
 * ```php
996
 * F\lastIndexOf(['Hello', 'World'], [1, ['Hello', 'World'], true, ['Hello', 'World']]); //=> 3
997
 * F\lastIndexOf(['Hello'], [1, ['Hello', 'World'], true]); //=> -1
998
 * F\lastIndexOf('World', 'Hello World'); //=> 6
999
 * F\lastIndexOf('World !', 'Hello World'); //=> -1
1000
 * F\lastIndexOf('foo', (object) ['name' => 'foo', 'age' => 11]); //=> 'name'
1001
 * ```
1002
 *
1003
 * @stream
1004
 * @signature a -> [a] -> Number
1005
 * @signature String -> String -> Number
1006
 * @param  mixed $item
0 ignored issues
show
Bug introduced by
There is no parameter named $item. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1007
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1008
 * @return int
1009
 */
1010 View Code Duplication
function lastIndexOf() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1011
    static $lastIndexOf = false;
1012
    $lastIndexOf = $lastIndexOf ?: curry(function($item, $list) {
1013
        if (is_string($list)) {
1014
            $index = strrpos($list, $item);
1015
        } else {
1016
            $index = findLastIndex(equals($item), $list);
1017
        }
1018
        return (false === $index || null === $index)
1019
            ? -1
1020
            : $index;
1021
    });
1022
    return _apply($lastIndexOf, func_get_args());
1023
}
1024
1025
/**
1026
 * Removes duplicates from a list.
1027
 *
1028
 * keeps the first occurence of each group of items which are
1029
 * equivalent according to the given `$areEqual` callable.
1030
 * ```php
1031
 * F\uniqueBy(F\eq(), [1, '2', '1', 3, '3', 2, 2]); //=> [1, '2', 3]
1032
 * ```
1033
 *
1034
 * @stream
1035
 * @signature (a -> a -> Boolean) -> [a] -> [a]
1036
 * @param  callable $areEqual
0 ignored issues
show
Bug introduced by
There is no parameter named $areEqual. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1037
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1038
 * @return array
1039
 */
1040
function uniqueBy() {
1041
    static $uniqueBy = false;
1042
    $uniqueBy = $uniqueBy ?: curry(function($areEqual, $list) {
1043
        // make sure the compare function is curried
1044
        $compare = function($a) use($areEqual) {
1045
            return function($b) use($areEqual, $a) {
1046
                return $areEqual($a, $b);
1047
            };
1048
        };
1049
1050
        return reduce(function($result, $item) use($compare) {
1051
            return (null === findIndex($compare($item), $result))
1052
                ? append($item, $result)
1053
                : $result;
1054
        }, [], $list);
1055
    });
1056
    return _apply($uniqueBy, func_get_args());
1057
}
1058
1059
/**
1060
 * Alias of `F\uniqueBy(F\equals())`.
1061
 *
1062
 * ```php
1063
 * F\unique([1, '1', [1, 2], 1, ['1', 2], [1, 2]]); //=> [1, '1', [1, 2], ['1', 2]]
1064
 * ```
1065
 *
1066
 * @stream
1067
 * @signature [a] -> [a]
1068
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1069
 * @return array
1070
 */
1071
function unique() {
1072
    static $unique = false;
1073
    $unique = $unique ?: uniqueBy(equals());
1074
    return _apply($unique, func_get_args());
1075
}
1076
1077
/**
1078
 * Converts an array to an associative array, based on the result of calling `$fn`
1079
 * on each element, and grouping the results according to values returned.
1080
 *
1081
 * Note that `$fn` should take an item from the list and return a string.
1082
 * ```php
1083
 * $persons = [
1084
 *     ['name' => 'foo', 'age' => 11],
1085
 *     ['name' => 'bar', 'age' => 9],
1086
 *     ['name' => 'baz', 'age' => 16],
1087
 *     ['name' => 'zeta', 'age' => 33],
1088
 *     ['name' => 'beta', 'age' => 25]
1089
 * ];
1090
 * $phase = function($person) {
1091
 *     $age = $person['age'];
1092
 *     if ($age < 13) return 'child';
1093
 *     if ($age < 19) return 'teenager';
1094
 *     return 'adult';
1095
 * };
1096
 * F\groupBy($phase, $persons); //=> ['child' => [['name' => 'foo', 'age' => 11], ['name' => 'bar', 'age' => 9]], 'teenager' => [['name' => 'baz', 'age' => 16]], 'adult' => [['name' => 'zeta', 'age' => 33], ['name' => 'beta', 'age' => 25]]]
1097
 * ```
1098
 *
1099
 * @stream
1100
 * @signature (a -> String) -> [a] -> {String: a}
1101
 * @param  callable $fn
0 ignored issues
show
Bug introduced by
There is no parameter named $fn. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1102
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1103
 * @return array
1104
 */
1105
function groupBy() {
1106
    static $groupBy = false;
1107
    $groupBy = $groupBy ?: curry(function($fn, $list) {
1108
        return reduce(function($result, $item) use($fn) {
1109
            $index = $fn($item);
1110
            if (! isset($result[$index]))
1111
                $result[$index] = [];
1112
            $result[$index][] = $item;
1113
            return $result;
1114
        }, [], $list);
1115
    });
1116
    return _apply($groupBy, func_get_args());
1117
}
1118
1119
/**
1120
 * Makes list of pairs from two lists.
1121
 *
1122
 * ```php
1123
 * F\pairsFrom([1, 2, 3], ['foo', 'bar', 'baz']); //=> [[1, 'foo'], [2, 'bar'], [3, 'baz']]
1124
 * F\pairsFrom([1, 2, 3], ['foo', 'bar']); //=> [[1, 'foo'], [2, 'bar']]
1125
 * F\pairsFrom([1, 3], ['foo', 'bar', 'baz']); //=> [[1, 'foo'], [3, 'bar']]
1126
 * F\pairsFrom([], ['foo', 'bar', 'baz']); //=> []
1127
 * ```
1128
 *
1129
 * @stream
1130
 * @signature [a] -> [b] -> [[a,b]]
1131
 * @param  array $list1
0 ignored issues
show
Bug introduced by
There is no parameter named $list1. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1132
 * @param  array $list2
0 ignored issues
show
Bug introduced by
There is no parameter named $list2. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1133
 * @return array
1134
 */
1135
function pairsFrom() {
1136
    static $pairsFrom = false;
1137
    $pairsFrom = $pairsFrom ?: curry(function($list1, $list2) {
1138
        $length1 = length($list1);
1139
        $length2 = length($list2);
1140
        if (0 == $length1 || 0 == $length2)
1141
            return [];
1142
        $list1 = values($list1);
1143
        $list2 = values($list2);
1144
        return map(function($index) use($list1, $list2) {
1145
            return [$list1[$index], $list2[$index]];
1146
        }, range(0, -1 + min($length1, $length2)));
1147
    });
1148
    return _apply($pairsFrom, func_get_args());
1149
}
1150
1151
/**
1152
 * Returns a copy of the given list, ordered using the given comparaison function.
1153
 *
1154
 * The `$compare` function should take two elements from the list and return `true`
1155
 * if the first element should be placed before the second element in the sorted
1156
 * list; and return `false` otherwise.
1157
 *
1158
 * **Note** This function is calling `usort` to sort elements, so:
1159
 *
1160
 * - if two elements `$a` and `$b` of the list are considered equal
1161
 * (ie `$compare($a, $b) == false` and `$compare($b, $a) == false`) then their
1162
 * order in the resulting array is undefined.
1163
 *
1164
 * - This function assigns new keys to the elements in array. It will remove any
1165
 * existing keys that may have been assigned, rather than just reordering the keys.
1166
 * ```php
1167
 * $numbers = [4, 5, 1, 3, 1, 2, 5];
1168
 * F\sort(F\lt(), $numbers); //=> [1, 1, 2, 3, 4, 5, 5]
1169
 * F\sort(F\gt(), $numbers); //=> [5, 5, 4, 3, 2, 1, 1]
1170
 * ```
1171
 *
1172
 * @stream
1173
 * @signature (a -> a -> Boolean) -> [a] -> [a]
1174
 * @param  callable $compare
1 ignored issue
show
Bug introduced by
There is no parameter named $compare. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1175
 * @param  array $list
0 ignored issues
show
Bug introduced by
There is no parameter named $list. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1176
 * @return array
1177
 */
1178
function sort() {
1179
    static $sort = false;
1180
    $sort = $sort ?: curry(function($compare, $list) {
1181
        $result = clone_($list);
1182
        usort($result, comparator($compare));
1183
        return $result;
1184
    });
1185
    return _apply($sort, func_get_args());
1186
}
1187