diff --git a/CHANGELOG.md b/CHANGELOG.md index 21a815c..05a89c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,14 @@ # Changelog -## v0.2.3-dev +## v0.2.3 -**2022-??-?? — [Diff](https://github.com/maciejczyzewski/bottomline/compare/0.2.2...0.2.3) — [Docs](https://maciejczyzewski.github.io/bottomline/)** +**2022-03-01 — [Diff](https://github.com/maciejczyzewski/bottomline/compare/0.2.2...0.2.3) — [Docs](https://maciejczyzewski.github.io/bottomline/)** * Updates to the `__::slug()` function, - Optimized to be more performant when given plain, old ASCII text - Has a workaround for [a bug in PHP 8.1](https://github.com/php/php-src/issues/7898) that would return an empty string -* Added `__::dropWhile`, `__::dropRight`, and `dropRightWhile` +* Added `__::dropWhile`, `__::dropRight`, and `__::dropRightWhile` +* Fix error in `__::mapKeys` that affected PHP 5.5 ## v0.2.2 diff --git a/docs/_data/fxn_registry.json b/docs/_data/fxn_registry.json index 8dbb8c5..a459013 100644 --- a/docs/_data/fxn_registry.json +++ b/docs/_data/fxn_registry.json @@ -182,7 +182,12 @@ "type": "int" } ], - "changelog": [], + "changelog": [ + { + "version": "0.2.3", + "message": "added to Bottomline" + } + ], "exceptions": [], "return": { "type": "array|\\Generator", @@ -214,7 +219,12 @@ "type": "\\Closure|float|int|string|bool" } ], - "changelog": [], + "changelog": [ + { + "version": "0.2.3", + "message": "added to Bottomline" + } + ], "exceptions": [], "return": { "type": "array|\\Generator", @@ -246,7 +256,12 @@ "type": "\\Closure|float|int|string|bool" } ], - "changelog": [], + "changelog": [ + { + "version": "0.2.3", + "message": "added to Bottomline" + } + ], "exceptions": [], "return": { "type": "array|\\Generator", diff --git a/src/__/__.php b/src/__/__.php index d47adfc..7152b8c 100644 --- a/src/__/__.php +++ b/src/__/__.php @@ -18,7 +18,7 @@ ** Sequences [1] ***************************************************************** - * bottomline v0.2.1 * + * bottomline v0.2.3 * * bottomline is licensed under the MIT license * * Copyright (c) 2014 Maciej A. Czyzewski * *****************************************************************/ @@ -33,9 +33,9 @@ * @method static array|\Generator chunk(iterable $iterable, int $size = 1, bool $preserveKeys = false)
Creates an array of elements split into groups the length of $size
.
If array can't be split evenly, the final chunk will be the remaining elements. When $preserveKeys
is set to TRUE, keys will be preserved. Default is FALSE, which will reindex the chunk numerically.
Usage
__::chunk([1, 2, 3, 4, 5], 3);
Result
[[1, 2, 3], [4, 5]]
0.2.0
- iterable objects are now supported
\InvalidArgumentException
- when an non-array or non-traversable object is given for $iterable.
\Exception
- when an \IteratorAggregate
is given and getIterator()
throws an exception.
When given a \Traversable
object for $iterable
, a generator will be returned. Otherwise, an array will be returned.
Creates an array with all falsey values removed.
The following values are considered falsey:
false
null
0
""
undefined
NaN
Usage
__::compact([0, 1, false, 2, '', 3]);
Result
[1, 2, 3]
0.2.0
- iterable objects are now supported
Creates a slice of array with n elements dropped from the beginning.
Usage
__::drop([0, 1, 3, 5], 2);
Result
[3, 5]
0.2.0
- iterable objects are now supported
Creates a slice of an array with n elements dropped from the end.
If the provided iterator is an array, then an array will be returned. Otherwise, a Generator will be returned. In this latter case, the entire iterable will be buffered in memory. If the iterable contains many elements, then this could cause memory issues.
Usage
__::dropRight([0, 1, 3, 5], 2);
Result
[0, 1]
An array containing a subset of the input array with front items matching the condition removed. If the provided iterable is not an array, then a Generator will be returned.
- * @method static array|\Generator dropRightWhile(iterable $input, \Closure|float|int|string|bool $condition)Creates a slice of the provided array with all elements matching the condition removed from the end.
If the provided iterator is an array, then an array will be returned. Otherwise, a Generator will be returned. In this latter case, the entire iterable will be buffered in memory. If the iterable contains many elements, then this could cause memory issues.
Drop by Primitive Condition
__::dropRightWhile([1, 2, 3, 3], 3);
Result
[1, 2]
Drop by Callback
__::dropRightWhile([1, 2, 3, 4, 5], static function ($item) {
return $item > 3;
});
Result
[1, 2, 3]
An array containing a subset of the input array with front items matching the condition removed. If the provided iterable is not an array, then a Generator will be returned.
- * @method static array|\Generator dropWhile(array|iterable $input, \Closure|float|int|string|bool $condition)Creates a slice of the provided array with all elements matching the condition removed from the front.
Drop by Primitive Condition
__::dropWhile([1, 1, 2, 3, 4], 1);
Result
[2, 3, 4]
Drop by Callback
__::dropWhile([1, 2, 3, 4, 5], static function ($item) {
return $item < 3;
});
Result
[3, 4, 5]
An array containing a subset of the input array with front items matching the condition removed. If the input was not an array, then a \Generator will be returned.
+ * @method static array|\Generator dropRight(iterable $input, int $number = 1)Creates a slice of an array with n elements dropped from the end.
If the provided iterator is an array, then an array will be returned. Otherwise, a Generator will be returned. In this latter case, the entire iterable will be buffered in memory. If the iterable contains many elements, then this could cause memory issues.
Usage
__::dropRight([0, 1, 3, 5], 2);
Result
[0, 1]
0.2.3
- added to Bottomline
An array containing a subset of the input array with front items matching the condition removed. If the provided iterable is not an array, then a Generator will be returned.
+ * @method static array|\Generator dropRightWhile(iterable $input, \Closure|float|int|string|bool $condition)Creates a slice of the provided array with all elements matching the condition removed from the end.
If the provided iterator is an array, then an array will be returned. Otherwise, a Generator will be returned. In this latter case, the entire iterable will be buffered in memory. If the iterable contains many elements, then this could cause memory issues.
Drop by Primitive Condition
__::dropRightWhile([1, 2, 3, 3], 3);
Result
[1, 2]
Drop by Callback
__::dropRightWhile([1, 2, 3, 4, 5], static function ($item) {
return $item > 3;
});
Result
[1, 2, 3]
0.2.3
- added to Bottomline
An array containing a subset of the input array with front items matching the condition removed. If the provided iterable is not an array, then a Generator will be returned.
+ * @method static array|\Generator dropWhile(array|iterable $input, \Closure|float|int|string|bool $condition)Creates a slice of the provided array with all elements matching the condition removed from the front.
Drop by Primitive Condition
__::dropWhile([1, 1, 2, 3, 4], 1);
Result
[2, 3, 4]
Drop by Callback
__::dropWhile([1, 2, 3, 4, 5], static function ($item) {
return $item < 3;
});
Result
[3, 4, 5]
0.2.3
- added to Bottomline
An array containing a subset of the input array with front items matching the condition removed. If the input was not an array, then a \Generator will be returned.
* @method static array|\Generator flatten(iterable $iterable, bool $shallow = false)Flattens a multidimensional array or iterable.
If $shallow
is set to TRUE, the array will only be flattened a single level.
Usage
__::flatten([1, 2, [3, [4]]], false);
Result
[1, 2, 3, 4]
0.2.0
- iterable objects are now supported
Patches array by xpath.
Usage
__::patch(
[
'addr' => [
'country' => 'US',
'zip' => 12345
]
],
[
'/addr/country' => 'CA',
'/addr/zip' => 54321
]
);
Result
['addr' => ['country' => 'CA', 'zip' => 54321]]
Returns patched array
* @method static array prepend(array $array, mixed $value = null)Prepend item or value to an array.
Usage
__::prepend([1, 2, 3], 4);
Result
[4, 1, 2, 3]
diff --git a/src/__/arrays/dropRight.php b/src/__/arrays/dropRight.php
index e13df98..fbb4cb5 100644
--- a/src/__/arrays/dropRight.php
+++ b/src/__/arrays/dropRight.php
@@ -64,6 +64,8 @@ function dropRightArray($input, $number)
* @see dropWhile
* @see dropRightWhile
*
+ * @since 0.2.3 added to Bottomline
+ *
* @return array|\Generator An array containing a subset of the input array with front items matching the condition
* removed. If the provided iterable is not an array, then a Generator will be returned.
*/
diff --git a/src/__/arrays/dropRightWhile.php b/src/__/arrays/dropRightWhile.php
index f5e1caa..caa4fbf 100644
--- a/src/__/arrays/dropRightWhile.php
+++ b/src/__/arrays/dropRightWhile.php
@@ -87,6 +87,8 @@ function dropArrayRightWhile($input, $comparison)
* @see dropRight
* @see dropRightWhile
*
+ * @since 0.2.3 added to Bottomline
+ *
* @return array|\Generator An array containing a subset of the input array with front items matching the condition
* removed. If the provided iterable is not an array, then a Generator will be returned.
*/
diff --git a/src/__/arrays/dropWhile.php b/src/__/arrays/dropWhile.php
index 81d4af4..94c64a6 100644
--- a/src/__/arrays/dropWhile.php
+++ b/src/__/arrays/dropWhile.php
@@ -91,6 +91,8 @@ function dropArrayWhile($input, $comparison)
* @see dropRight
* @see dropRightWhile
*
+ * @since 0.2.3 added to Bottomline
+ *
* @return array|\Generator An array containing a subset of the input array with front
* items matching the condition removed. If the input was not an array, then a \Generator
* will be returned.
diff --git a/src/__/sequences/BottomlineWrapper.php b/src/__/sequences/BottomlineWrapper.php
index ad5faf5..689330d 100644
--- a/src/__/sequences/BottomlineWrapper.php
+++ b/src/__/sequences/BottomlineWrapper.php
@@ -8,9 +8,9 @@
* @method static \BottomlineWrapper chunk(int $size = 1, bool $preserveKeys = false) Creates an array of elements split into groups the length of $size
.
If array can't be split evenly, the final chunk will be the remaining elements. When $preserveKeys
is set to TRUE, keys will be preserved. Default is FALSE, which will reindex the chunk numerically.
Usage
__::chunk([1, 2, 3, 4, 5], 3);
Result
[[1, 2, 3], [4, 5]]
0.2.0
- iterable objects are now supported
\InvalidArgumentException
- when an non-array or non-traversable object is given for $iterable.
\Exception
- when an \IteratorAggregate
is given and getIterator()
throws an exception.
When given a \Traversable
object for $iterable
, a generator will be returned. Otherwise, an array will be returned.
Creates an array with all falsey values removed.
The following values are considered falsey:
false
null
0
""
undefined
NaN
Usage
__::compact([0, 1, false, 2, '', 3]);
Result
[1, 2, 3]
0.2.0
- iterable objects are now supported
Creates a slice of array with n elements dropped from the beginning.
Usage
__::drop([0, 1, 3, 5], 2);
Result
[3, 5]
0.2.0
- iterable objects are now supported
Creates a slice of an array with n elements dropped from the end.
If the provided iterator is an array, then an array will be returned. Otherwise, a Generator will be returned. In this latter case, the entire iterable will be buffered in memory. If the iterable contains many elements, then this could cause memory issues.
Usage
__::dropRight([0, 1, 3, 5], 2);
Result
[0, 1]
An array containing a subset of the input array with front items matching the condition removed. If the provided iterable is not an array, then a Generator will be returned.
- * @method static \BottomlineWrapper dropRightWhile(\Closure|float|int|string|bool $condition)Creates a slice of the provided array with all elements matching the condition removed from the end.
If the provided iterator is an array, then an array will be returned. Otherwise, a Generator will be returned. In this latter case, the entire iterable will be buffered in memory. If the iterable contains many elements, then this could cause memory issues.
Drop by Primitive Condition
__::dropRightWhile([1, 2, 3, 3], 3);
Result
[1, 2]
Drop by Callback
__::dropRightWhile([1, 2, 3, 4, 5], static function ($item) {
return $item > 3;
});
Result
[1, 2, 3]
An array containing a subset of the input array with front items matching the condition removed. If the provided iterable is not an array, then a Generator will be returned.
- * @method static \BottomlineWrapper dropWhile(\Closure|float|int|string|bool $condition)Creates a slice of the provided array with all elements matching the condition removed from the front.
Drop by Primitive Condition
__::dropWhile([1, 1, 2, 3, 4], 1);
Result
[2, 3, 4]
Drop by Callback
__::dropWhile([1, 2, 3, 4, 5], static function ($item) {
return $item < 3;
});
Result
[3, 4, 5]
An array containing a subset of the input array with front items matching the condition removed. If the input was not an array, then a \Generator will be returned.
+ * @method static \BottomlineWrapper dropRight(int $number = 1)Creates a slice of an array with n elements dropped from the end.
If the provided iterator is an array, then an array will be returned. Otherwise, a Generator will be returned. In this latter case, the entire iterable will be buffered in memory. If the iterable contains many elements, then this could cause memory issues.
Usage
__::dropRight([0, 1, 3, 5], 2);
Result
[0, 1]
0.2.3
- added to Bottomline
An array containing a subset of the input array with front items matching the condition removed. If the provided iterable is not an array, then a Generator will be returned.
+ * @method static \BottomlineWrapper dropRightWhile(\Closure|float|int|string|bool $condition)Creates a slice of the provided array with all elements matching the condition removed from the end.
If the provided iterator is an array, then an array will be returned. Otherwise, a Generator will be returned. In this latter case, the entire iterable will be buffered in memory. If the iterable contains many elements, then this could cause memory issues.
Drop by Primitive Condition
__::dropRightWhile([1, 2, 3, 3], 3);
Result
[1, 2]
Drop by Callback
__::dropRightWhile([1, 2, 3, 4, 5], static function ($item) {
return $item > 3;
});
Result
[1, 2, 3]
0.2.3
- added to Bottomline
An array containing a subset of the input array with front items matching the condition removed. If the provided iterable is not an array, then a Generator will be returned.
+ * @method static \BottomlineWrapper dropWhile(\Closure|float|int|string|bool $condition)Creates a slice of the provided array with all elements matching the condition removed from the front.
Drop by Primitive Condition
__::dropWhile([1, 1, 2, 3, 4], 1);
Result
[2, 3, 4]
Drop by Callback
__::dropWhile([1, 2, 3, 4, 5], static function ($item) {
return $item < 3;
});
Result
[3, 4, 5]
0.2.3
- added to Bottomline
An array containing a subset of the input array with front items matching the condition removed. If the input was not an array, then a \Generator will be returned.
* @method static \BottomlineWrapper flatten(bool $shallow = false)Flattens a multidimensional array or iterable.
If $shallow
is set to TRUE, the array will only be flattened a single level.
Usage
__::flatten([1, 2, [3, [4]]], false);
Result
[1, 2, 3, 4]
0.2.0
- iterable objects are now supported
Patches array by xpath.
Usage
__::patch(
[
'addr' => [
'country' => 'US',
'zip' => 12345
]
],
[
'/addr/country' => 'CA',
'/addr/zip' => 54321
]
);
Result
['addr' => ['country' => 'CA', 'zip' => 54321]]
Returns patched array
* @method static \BottomlineWrapper prepend(mixed $value = null)Prepend item or value to an array.
Usage
__::prepend([1, 2, 3], 4);
Result
[4, 1, 2, 3]