Skip to content

Commit f6bdc99

Browse files
committed
Remove separate indexed versions of collection functions
1 parent dcf1e9a commit f6bdc99

File tree

6 files changed

+30
-567
lines changed

6 files changed

+30
-567
lines changed

src/Builder/InnerFunctions.php

-108
Original file line numberDiff line numberDiff line change
@@ -444,27 +444,6 @@ public static function each(callable $function, $collection)
444444
return $collection;
445445
}
446446

447-
/**
448-
* Calls the given function for each element in the collection and returns the original collection.
449-
*
450-
* Like `each`, but the supplied `function` receives three arguments: `item`, `index`, `collection`.
451-
*
452-
* @param callable $function
453-
* @param array|\Traversable|Collection $collection
454-
*
455-
* @return array|\Traversable|Collection
456-
*
457-
* @deprecated Since version 0.4, to be removed in 0.5. The callback of `each` now receives three arguments as well.
458-
*/
459-
public static function eachIndexed(callable $function, $collection)
460-
{
461-
foreach ($collection as $key => $item) {
462-
$function($item, $key, $collection);
463-
}
464-
465-
return $collection;
466-
}
467-
468447
/**
469448
* Returns a function that returns `true` when either of the predicates matches, `false` otherwise.
470449
*
@@ -562,23 +541,6 @@ public static function filter(callable $predicate, $collection)
562541
return static::_filter($predicate, $collection);
563542
}
564543

565-
/**
566-
* Returns a new collection containing the items that match the given predicate.
567-
*
568-
* Like `filter`, but the supplied `predicate` receives three arguments: `item`, `index`, `collection`.
569-
*
570-
* @param callable $predicate
571-
* @param array|\Traversable|Collection $collection
572-
*
573-
* @return array|Collection
574-
*
575-
* @deprecated Since version 0.4, to be removed in 0.5. The callback of `filter` now receives three arguments as well.
576-
*/
577-
public static function filterIndexed(callable $predicate, $collection)
578-
{
579-
return static::_filter($predicate, $collection);
580-
}
581-
582544
/**
583545
* Returns the first item of a collection for which the given predicate matches, or null if no match is found.
584546
*
@@ -965,23 +927,6 @@ public static function map(callable $function, $collection)
965927
return static::_map($function, $collection);
966928
}
967929

968-
/**
969-
* Returns a new collection where values are created from the original collection by calling the supplied function.
970-
*
971-
* Like `map`, but the supplied `function` receives three arguments: `item`, `index`, `collection`.
972-
*
973-
* @param callable $function
974-
* @param array|\Traversable|Collection $collection
975-
*
976-
* @return array|Collection
977-
*
978-
* @deprecated Since version 0.4, to be removed in 0.5. The callback of `map` now receives three arguments as well.
979-
*/
980-
public static function mapIndexed(callable $function, $collection)
981-
{
982-
return static::_map($function, $collection);
983-
}
984-
985930
/**
986931
* Returns the largest value in the collection.
987932
*
@@ -1363,24 +1308,6 @@ public static function reduce(callable $function, $initial, $collection)
13631308
return static::_reduce($function, $initial, $collection);
13641309
}
13651310

1366-
/**
1367-
* Returns a value accumulated by calling the given function for each element of the collection.
1368-
*
1369-
* Like `reduce`, but the supplied `function` receives four arguments: `previousValue`, `item`, `index`, `collection`.
1370-
*
1371-
* @param callable $function
1372-
* @param mixed $initial
1373-
* @param array|\Traversable $collection
1374-
*
1375-
* @return mixed
1376-
*
1377-
* @deprecated Since version 0.4, to be removed in 0.5. The callback of `reduce` now receives four arguments as well.
1378-
*/
1379-
public static function reduceIndexed(callable $function, $initial, $collection)
1380-
{
1381-
return static::_reduce($function, $initial, $collection);
1382-
}
1383-
13841311
/**
13851312
* Returns a value accumulated by calling the given function for each element of the collection in reverse order.
13861313
*
@@ -1397,24 +1324,6 @@ public static function reduceRight(callable $function, $initial, $collection)
13971324
return static::_reduce($function, $initial, static::_reverse($collection));
13981325
}
13991326

1400-
/**
1401-
* Returns a value accumulated by calling the given function for each element of the collection in reverse order.
1402-
*
1403-
* Like `reduceRight`, but the supplied `function` receives four arguments: `previousValue`, `item`, `index`, `collection`.
1404-
*
1405-
* @param callable $function
1406-
* @param mixed $initial
1407-
* @param array|\Traversable $collection
1408-
*
1409-
* @return mixed
1410-
*
1411-
* @deprecated Since version 0.4, to be removed in 0.5. The callback of `reduceRight` now receives four arguments as well.
1412-
*/
1413-
public static function reduceRightIndexed(callable $function, $initial, $collection)
1414-
{
1415-
return static::_reduce($function, $initial, static::_reverse($collection));
1416-
}
1417-
14181327
/**
14191328
* Returns a new collection containing the items that do not match the given predicate.
14201329
*
@@ -1430,23 +1339,6 @@ public static function reject(callable $predicate, $collection)
14301339
return static::_filter(Phamda::not($predicate), $collection);
14311340
}
14321341

1433-
/**
1434-
* Returns a new collection containing the items that do not match the given predicate.
1435-
*
1436-
* Like `reject`, but the supplied `predicate` receives three arguments: `item`, `index`, `collection`.
1437-
*
1438-
* @param callable $predicate
1439-
* @param array|\Traversable|Collection $collection
1440-
*
1441-
* @return array|Collection
1442-
*
1443-
* @deprecated Since version 0.4, to be removed in 0.5. The callback of `reject` now receives three arguments as well.
1444-
*/
1445-
public static function rejectIndexed(callable $predicate, $collection)
1446-
{
1447-
return static::_filter(Phamda::not($predicate), $collection);
1448-
}
1449-
14501342
/**
14511343
* Returns a new collection where the items are in a reverse order.
14521344
*

src/Phamda.php

+6-156
Original file line numberDiff line numberDiff line change
@@ -630,47 +630,17 @@ public static function divide($x = null, $y = null)
630630
*
631631
* ```php
632632
* $date = new \DateTime('2015-02-02');
633-
* $addDays = function ($number) use ($date) { $date->modify("+{$number} days"); };
634-
* P::each($addDays, [3, 6, 2]);
635-
* $date->format('Y-m-d'); // => '2015-02-13'
636-
* ```
637-
*
638-
* @param callable $function
639-
* @param array|\Traversable|Collection $collection
640-
*
641-
* @return callable|array|\Traversable|Collection
642-
*/
643-
public static function each($function = null, $collection = null)
644-
{
645-
return static::curry2(function (callable $function, $collection) {
646-
foreach ($collection as $key => $item) {
647-
$function($item, $key, $collection);
648-
}
649-
650-
return $collection;
651-
}, func_get_args());
652-
}
653-
654-
/**
655-
* Calls the given function for each element in the collection and returns the original collection.
656-
*
657-
* Like `each`, but the supplied `function` receives three arguments: `item`, `index`, `collection`.
658-
*
659-
* ```php
660-
* $date = new \DateTime('2015-02-02');
661633
* $addCalendar = function ($number, $type) use ($date) { $date->modify("+{$number} {$type}"); };
662-
* P::eachIndexed($addCalendar, ['months' => 3, 'weeks' => 6, 'days' => 2]);
634+
* P::each($addCalendar, ['months' => 3, 'weeks' => 6, 'days' => 2]);
663635
* $date->format('Y-m-d'); // => '2015-06-15'
664636
* ```
665637
*
666638
* @param callable $function
667639
* @param array|\Traversable|Collection $collection
668640
*
669641
* @return callable|array|\Traversable|Collection
670-
*
671-
* @deprecated Since version 0.4, to be removed in 0.5. The callback of `each` now receives three arguments as well.
672642
*/
673-
public static function eachIndexed($function = null, $collection = null)
643+
public static function each($function = null, $collection = null)
674644
{
675645
return static::curry2(function (callable $function, $collection) {
676646
foreach ($collection as $key => $item) {
@@ -821,30 +791,6 @@ public static function filter($predicate = null, $collection = null)
821791
}, func_get_args());
822792
}
823793

824-
/**
825-
* Returns a new collection containing the items that match the given predicate.
826-
*
827-
* Like `filter`, but the supplied `predicate` receives three arguments: `item`, `index`, `collection`.
828-
*
829-
* ```php
830-
* $smallerThanNext = function ($value, $key, $list) { return isset($list[$key + 1]) ? $value < $list[$key + 1] : false; };
831-
* P::filterIndexed($smallerThanNext, [3, 6, 2, 19]); // => [0 => 3, 2 => 2]
832-
* ```
833-
*
834-
* @param callable $predicate
835-
* @param array|\Traversable|Collection $collection
836-
*
837-
* @return callable|array|Collection
838-
*
839-
* @deprecated Since version 0.4, to be removed in 0.5. The callback of `filter` now receives three arguments as well.
840-
*/
841-
public static function filterIndexed($predicate = null, $collection = null)
842-
{
843-
return static::curry2(function (callable $predicate, $collection) {
844-
return static::_filter($predicate, $collection);
845-
}, func_get_args());
846-
}
847-
848794
/**
849795
* Returns the first item of a collection for which the given predicate matches, or null if no match is found.
850796
*
@@ -1399,38 +1345,16 @@ public static function lte($x = null, $y = null)
13991345
* ```php
14001346
* $square = function ($x) { return $x ** 2; };
14011347
* P::map($square, [1, 2, 3, 4]); // => [1, 4, 9, 16]
1402-
* ```
1403-
*
1404-
* @param callable $function
1405-
* @param array|\Traversable|Collection $collection
1406-
*
1407-
* @return callable|array|Collection
1408-
*/
1409-
public static function map($function = null, $collection = null)
1410-
{
1411-
return static::curry2(function (callable $function, $collection) {
1412-
return static::_map($function, $collection);
1413-
}, func_get_args());
1414-
}
1415-
1416-
/**
1417-
* Returns a new collection where values are created from the original collection by calling the supplied function.
1418-
*
1419-
* Like `map`, but the supplied `function` receives three arguments: `item`, `index`, `collection`.
1420-
*
1421-
* ```php
14221348
* $keyExp = function ($value, $key) { return $value ** $key; };
1423-
* P::mapIndexed($keyExp, [1, 2, 3, 4]); // => [1, 2, 9, 64]
1349+
* P::map($keyExp, [1, 2, 3, 4]); // => [1, 2, 9, 64]
14241350
* ```
14251351
*
14261352
* @param callable $function
14271353
* @param array|\Traversable|Collection $collection
14281354
*
14291355
* @return callable|array|Collection
1430-
*
1431-
* @deprecated Since version 0.4, to be removed in 0.5. The callback of `map` now receives three arguments as well.
14321356
*/
1433-
public static function mapIndexed($function = null, $collection = null)
1357+
public static function map($function = null, $collection = null)
14341358
{
14351359
return static::curry2(function (callable $function, $collection) {
14361360
return static::_map($function, $collection);
@@ -2020,73 +1944,23 @@ public static function reduce($function = null, $initial = null, $collection = n
20201944
}, func_get_args());
20211945
}
20221946

2023-
/**
2024-
* Returns a value accumulated by calling the given function for each element of the collection.
2025-
*
2026-
* Like `reduce`, but the supplied `function` receives four arguments: `previousValue`, `item`, `index`, `collection`.
2027-
*
2028-
* ```php
2029-
* $concat = function ($accumulator, $value, $key) { return $accumulator . $key . $value; };
2030-
* P::reduceIndexed($concat, 'no', ['foo' => 'bar', 'fiz' => 'buz']); // => 'nofoobarfizbuz'
2031-
* ```
2032-
*
2033-
* @param callable $function
2034-
* @param mixed $initial
2035-
* @param array|\Traversable $collection
2036-
*
2037-
* @return callable|mixed
2038-
*
2039-
* @deprecated Since version 0.4, to be removed in 0.5. The callback of `reduce` now receives four arguments as well.
2040-
*/
2041-
public static function reduceIndexed($function = null, $initial = null, $collection = null)
2042-
{
2043-
return static::curry3(function (callable $function, $initial, $collection) {
2044-
return static::_reduce($function, $initial, $collection);
2045-
}, func_get_args());
2046-
}
2047-
20481947
/**
20491948
* Returns a value accumulated by calling the given function for each element of the collection in reverse order.
20501949
*
20511950
* The supplied `function` receives four arguments: `previousValue`, `item`, `index`, `collection`.
20521951
*
20531952
* ```php
2054-
* $concat = function ($x, $y) { return $x . $y; };
2055-
* P::reduceRight($concat, 'foo', ['bar', 'baz']); // => 'foobazbar'
2056-
* ```
2057-
*
2058-
* @param callable $function
2059-
* @param mixed $initial
2060-
* @param array|\Traversable $collection
2061-
*
2062-
* @return callable|mixed
2063-
*/
2064-
public static function reduceRight($function = null, $initial = null, $collection = null)
2065-
{
2066-
return static::curry3(function (callable $function, $initial, $collection) {
2067-
return static::_reduce($function, $initial, static::_reverse($collection));
2068-
}, func_get_args());
2069-
}
2070-
2071-
/**
2072-
* Returns a value accumulated by calling the given function for each element of the collection in reverse order.
2073-
*
2074-
* Like `reduceRight`, but the supplied `function` receives four arguments: `previousValue`, `item`, `index`, `collection`.
2075-
*
2076-
* ```php
20771953
* $concat = function ($accumulator, $value, $key) { return $accumulator . $key . $value; };
2078-
* P::reduceRightIndexed($concat, 'no', ['foo' => 'bar', 'fiz' => 'buz']); // => 'nofizbuzfoobar'
1954+
* P::reduceRight($concat, 'no', ['foo' => 'bar', 'fiz' => 'buz']); // => 'nofizbuzfoobar'
20791955
* ```
20801956
*
20811957
* @param callable $function
20821958
* @param mixed $initial
20831959
* @param array|\Traversable $collection
20841960
*
20851961
* @return callable|mixed
2086-
*
2087-
* @deprecated Since version 0.4, to be removed in 0.5. The callback of `reduceRight` now receives four arguments as well.
20881962
*/
2089-
public static function reduceRightIndexed($function = null, $initial = null, $collection = null)
1963+
public static function reduceRight($function = null, $initial = null, $collection = null)
20901964
{
20911965
return static::curry3(function (callable $function, $initial, $collection) {
20921966
return static::_reduce($function, $initial, static::_reverse($collection));
@@ -2115,30 +1989,6 @@ public static function reject($predicate = null, $collection = null)
21151989
}, func_get_args());
21161990
}
21171991

2118-
/**
2119-
* Returns a new collection containing the items that do not match the given predicate.
2120-
*
2121-
* Like `reject`, but the supplied `predicate` receives three arguments: `item`, `index`, `collection`.
2122-
*
2123-
* ```php
2124-
* $smallerThanNext = function ($value, $key, $list) { return isset($list[$key + 1]) ? $value < $list[$key + 1] : false; };
2125-
* P::rejectIndexed($smallerThanNext, [3, 6, 2, 19]); // => [1 => 6, 3 => 19]
2126-
* ```
2127-
*
2128-
* @param callable $predicate
2129-
* @param array|\Traversable|Collection $collection
2130-
*
2131-
* @return callable|array|Collection
2132-
*
2133-
* @deprecated Since version 0.4, to be removed in 0.5. The callback of `reject` now receives three arguments as well.
2134-
*/
2135-
public static function rejectIndexed($predicate = null, $collection = null)
2136-
{
2137-
return static::curry2(function (callable $predicate, $collection) {
2138-
return static::_filter(Phamda::not($predicate), $collection);
2139-
}, func_get_args());
2140-
}
2141-
21421992
/**
21431993
* Returns a new collection where the items are in a reverse order.
21441994
*

0 commit comments

Comments
 (0)