|
18 | 18 | ** Sequences [1] |
19 | 19 |
|
20 | 20 | ***************************************************************** |
21 | | - * bottomline v0.2.1 * |
| 21 | + * bottomline v0.2.3 * |
22 | 22 | * bottomline is licensed under the MIT license * |
23 | 23 | * Copyright (c) 2014 Maciej A. Czyzewski * |
24 | 24 | *****************************************************************/ |
|
33 | 33 | * @method static array|\Generator chunk(iterable $iterable, int $size = 1, bool $preserveKeys = false) <p>Creates an array of elements split into groups the length of <code>$size</code>.</p><br><p>If array can't be split evenly, the final chunk will be the remaining elements. When <code>$preserveKeys</code> is set to TRUE, keys will be preserved. Default is FALSE, which will reindex the chunk numerically.</p> <p><strong>Usage</strong></p> <pre><code class="language-php">__::chunk([1, 2, 3, 4, 5], 3);</code></pre> <p><strong>Result</strong></p> <pre><code>[[1, 2, 3], [4, 5]]</code></pre><h2>Changelog</h2><ul><li><p><code>0.2.0</code> - iterable objects are now supported</p></li></ul><h2>Exceptions</h2><ul><li><p><code>\InvalidArgumentException</code> - when an non-array or non-traversable object is given for $iterable.</p></li><li><p><code>\Exception</code> - when an <code>\IteratorAggregate</code> is given and <code>getIterator()</code> throws an exception.</p></li></ul><h2>Returns</h2><p>When given a <code>\Traversable</code> object for <code>$iterable</code>, a generator will be returned. Otherwise, an array will be returned.</p> |
34 | 34 | * @method static array|\Generator compact(iterable $iterable) <p>Creates an array with all falsey values removed.</p><br><p>The following values are considered falsey:</p> <ul> <li><code>false</code></li> <li><code>null</code></li> <li><code>0</code></li> <li><code>""</code></li> <li><code>undefined</code></li> <li><code>NaN</code></li> </ul> <p><strong>Usage</strong></p> <pre><code class="language-php">__::compact([0, 1, false, 2, '', 3]);</code></pre> <p><strong>Result</strong></p> <pre><code>[1, 2, 3]</code></pre><h2>Changelog</h2><ul><li><p><code>0.2.0</code> - iterable objects are now supported</p></li></ul> |
35 | 35 | * @method static array|\Generator drop(iterable $input, int $number = 1) <p>Creates a slice of array with n elements dropped from the beginning.</p><br><p><strong>Usage</strong></p> <pre><code class="language-php">__::drop([0, 1, 3, 5], 2);</code></pre> <p><strong>Result</strong></p> <pre><code>[3, 5]</code></pre><h2>Changelog</h2><ul><li><p><code>0.2.0</code> - iterable objects are now supported</p></li></ul> |
36 | | - * @method static array|\Generator dropRight(iterable $input, int $number = 1) <p>Creates a slice of an array with n elements dropped from the end.</p><br><p>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.</p> <p><strong>Usage</strong></p> <pre><code class="language-php">__::dropRight([0, 1, 3, 5], 2);</code></pre> <p><strong>Result</strong></p> <pre><code class="language-php">[0, 1]</code></pre><h2>Returns</h2><p>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.</p> |
37 | | - * @method static array|\Generator dropRightWhile(iterable $input, \Closure|float|int|string|bool $condition) <p>Creates a slice of the provided array with all elements matching the condition removed from the end.</p><br><p>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.</p> <p><strong>Drop by Primitive Condition</strong></p> <pre><code class="language-php">__::dropRightWhile([1, 2, 3, 3], 3);</code></pre> <p><strong>Result</strong></p> <pre><code class="language-php">[1, 2]</code></pre> <p><strong>Drop by Callback</strong></p> <pre><code class="language-php">__::dropRightWhile([1, 2, 3, 4, 5], static function ($item) {<br /> return $item > 3;<br /> });</code></pre> <p><strong>Result</strong></p> <pre><code class="language-php">[1, 2, 3]</code></pre><h2>Returns</h2><p>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.</p> |
38 | | - * @method static array|\Generator dropWhile(array|iterable $input, \Closure|float|int|string|bool $condition) <p>Creates a slice of the provided array with all elements matching the condition removed from the front.</p><br><p><strong>Drop by Primitive Condition</strong></p> <pre><code class="language-php">__::dropWhile([1, 1, 2, 3, 4], 1);</code></pre> <p><strong>Result</strong></p> <pre><code class="language-php">[2, 3, 4]</code></pre> <p><strong>Drop by Callback</strong></p> <pre><code class="language-php">__::dropWhile([1, 2, 3, 4, 5], static function ($item) {<br /> return $item < 3;<br /> });</code></pre> <p><strong>Result</strong></p> <pre><code class="language-php">[3, 4, 5]</code></pre><h2>Returns</h2><p>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.</p> |
| 36 | + * @method static array|\Generator dropRight(iterable $input, int $number = 1) <p>Creates a slice of an array with n elements dropped from the end.</p><br><p>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.</p> <p><strong>Usage</strong></p> <pre><code class="language-php">__::dropRight([0, 1, 3, 5], 2);</code></pre> <p><strong>Result</strong></p> <pre><code class="language-php">[0, 1]</code></pre><h2>Changelog</h2><ul><li><p><code>0.2.3</code> - added to Bottomline</p></li></ul><h2>Returns</h2><p>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.</p> |
| 37 | + * @method static array|\Generator dropRightWhile(iterable $input, \Closure|float|int|string|bool $condition) <p>Creates a slice of the provided array with all elements matching the condition removed from the end.</p><br><p>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.</p> <p><strong>Drop by Primitive Condition</strong></p> <pre><code class="language-php">__::dropRightWhile([1, 2, 3, 3], 3);</code></pre> <p><strong>Result</strong></p> <pre><code class="language-php">[1, 2]</code></pre> <p><strong>Drop by Callback</strong></p> <pre><code class="language-php">__::dropRightWhile([1, 2, 3, 4, 5], static function ($item) {<br /> return $item > 3;<br /> });</code></pre> <p><strong>Result</strong></p> <pre><code class="language-php">[1, 2, 3]</code></pre><h2>Changelog</h2><ul><li><p><code>0.2.3</code> - added to Bottomline</p></li></ul><h2>Returns</h2><p>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.</p> |
| 38 | + * @method static array|\Generator dropWhile(array|iterable $input, \Closure|float|int|string|bool $condition) <p>Creates a slice of the provided array with all elements matching the condition removed from the front.</p><br><p><strong>Drop by Primitive Condition</strong></p> <pre><code class="language-php">__::dropWhile([1, 1, 2, 3, 4], 1);</code></pre> <p><strong>Result</strong></p> <pre><code class="language-php">[2, 3, 4]</code></pre> <p><strong>Drop by Callback</strong></p> <pre><code class="language-php">__::dropWhile([1, 2, 3, 4, 5], static function ($item) {<br /> return $item < 3;<br /> });</code></pre> <p><strong>Result</strong></p> <pre><code class="language-php">[3, 4, 5]</code></pre><h2>Changelog</h2><ul><li><p><code>0.2.3</code> - added to Bottomline</p></li></ul><h2>Returns</h2><p>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.</p> |
39 | 39 | * @method static array|\Generator flatten(iterable $iterable, bool $shallow = false) <p>Flattens a multidimensional array or iterable.</p><br><p>If <code>$shallow</code> is set to TRUE, the array will only be flattened a single level.</p> <p><strong>Usage</strong></p> <pre><code class="language-php">__::flatten([1, 2, [3, [4]]], false);</code></pre> <p><strong>Result</strong></p> <pre><code>[1, 2, 3, 4]</code></pre><h2>Changelog</h2><ul><li><p><code>0.2.0</code> - iterable objects are now supported</p></li></ul> |
40 | 40 | * @method static array patch(array $array, array $patches, string $parent = '') <p>Patches array by xpath.</p><br><p><strong>Usage</strong></p> <pre><code class="language-php">__::patch(<br /> [<br /> 'addr' => [<br /> 'country' => 'US',<br /> 'zip' => 12345<br /> ]<br /> ],<br /> [<br /> '/addr/country' => 'CA',<br /> '/addr/zip' => 54321<br /> ]<br /> );</code></pre> <p><strong>Result</strong></p> <pre><code>['addr' => ['country' => 'CA', 'zip' => 54321]]</code></pre><h2>Returns</h2><p>Returns patched array</p> |
41 | 41 | * @method static array prepend(array $array, mixed $value = null) <p>Prepend item or value to an array.</p><br><p><strong>Usage</strong></p> <pre><code class="language-php">__::prepend([1, 2, 3], 4);</code></pre> <p><strong>Result</strong></p> <pre><code>[4, 1, 2, 3]</code></pre> |
|
0 commit comments