diff --git a/CHANGELOG.md b/CHANGELOG.md index bf9881c..042b8f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # CHANGELOG +## 1.3 / not released + +* Added \nspl\a\lazy which contains lazy versions of function from \nspl\a where it made sense +* Added \nspl\a\in which works both on arrays and traversable objects +* Added \nspl\a\keys which works both on arrays and traversable objects +* Added \nspl\a\dropKeys which works both on arrays and traversable objects +* Added \nspl\a\diff which works both on arrays and traversable objects +* Added \nspl\a\intersect which works both on arrays and traversable objects +* Added \nspl\rnd\randomString +* Added \nspl\f\throttled higher order function + ## 1.2 / 2017-01-05 * Made ```\nspl\args``` PHP 7 compatible diff --git a/README.md b/README.md index c5ded72..78099ac 100644 --- a/README.md +++ b/README.md @@ -141,9 +141,9 @@ $pairs = a\zip([1, 2, 3], ['a', 'b', 'c']); * [reorder](#reorderarray-list-from-to) * [value](#valuearray-key-default--null) * [keys](#keyssequence) - * [in](#initem-collection) - * [diff](#diffcollction1-collection2) - * [intersect](#diffcollction1-collection2) + * [in](#initem-sequence) + * [diff](#diffcollction1-sequence2) + * [intersect](#diffcollction1-sequence2) * [isList](#islistvar) * [Callbacks](#callbacks-2) * [nspl\a\lazy](#nsplalazy) @@ -655,21 +655,21 @@ Returns list of the sequence keys assert(['a', 'b', 'c'] === keys(array('a' => 1, 'b' => 2, 'c' => 3))); ``` -##### in($item, $collection) +##### in($item, $sequence) Checks if the item is preset in array or traversable object ```php assert(true === in(1, [1, 2, 3]); ``` -##### diff($collection1, $collection2) +##### diff($sequence1, $sequence2) Computes the difference of arrays or traversable objects ```php assert([1] === diff([1, 2, 3], new ArrayObject([2, 3, 4])); ``` -##### intersect($collection1, $collection2) +##### intersect($sequence1, $sequence2) Computes the intersection of arrays or traversable objects ```php diff --git a/index.md b/index.md index c5ded72..78099ac 100644 --- a/index.md +++ b/index.md @@ -141,9 +141,9 @@ $pairs = a\zip([1, 2, 3], ['a', 'b', 'c']); * [reorder](#reorderarray-list-from-to) * [value](#valuearray-key-default--null) * [keys](#keyssequence) - * [in](#initem-collection) - * [diff](#diffcollction1-collection2) - * [intersect](#diffcollction1-collection2) + * [in](#initem-sequence) + * [diff](#diffcollction1-sequence2) + * [intersect](#diffcollction1-sequence2) * [isList](#islistvar) * [Callbacks](#callbacks-2) * [nspl\a\lazy](#nsplalazy) @@ -655,21 +655,21 @@ Returns list of the sequence keys assert(['a', 'b', 'c'] === keys(array('a' => 1, 'b' => 2, 'c' => 3))); ``` -##### in($item, $collection) +##### in($item, $sequence) Checks if the item is preset in array or traversable object ```php assert(true === in(1, [1, 2, 3]); ``` -##### diff($collection1, $collection2) +##### diff($sequence1, $sequence2) Computes the difference of arrays or traversable objects ```php assert([1] === diff([1, 2, 3], new ArrayObject([2, 3, 4])); ``` -##### intersect($collection1, $collection2) +##### intersect($sequence1, $sequence2) Computes the intersection of arrays or traversable objects ```php diff --git a/nspl/a.php b/nspl/a.php index 86f8776..a312902 100644 --- a/nspl/a.php +++ b/nspl/a.php @@ -866,22 +866,22 @@ function isList($var) * Checks if the item is preset in array or traversable object * * @param mixed $item - * @param array|\Traversable $collection + * @param array|\Traversable $sequence * @return mixed */ -function in($item, $collection) +function in($item, $sequence) { - if (is_array($collection)) { - return in_array($item, $collection); + if (is_array($sequence)) { + return in_array($item, $sequence); } - if (method_exists($collection, 'toArray')) { - return in_array($item, $collection->toArray()); + if (method_exists($sequence, 'toArray')) { + return in_array($item, $sequence->toArray()); } - args\expects(args\traversable, $collection); - foreach ($collection as $collectionItem) { - if ($collectionItem === $item) { + args\expects(args\traversable, $sequence); + foreach ($sequence as $sequenceItem) { + if ($sequenceItem === $item) { return true; } } @@ -893,30 +893,30 @@ function in($item, $collection) /** * Computes the difference of arrays or traversable objects * - * @param array|\Traversable $collection1 - * @param array|\Traversable $collection2 + * @param array|\Traversable $sequence1 + * @param array|\Traversable $sequence2 * @return array */ -function diff($collection1, $collection2) +function diff($sequence1, $sequence2) { - if (is_array($collection1)) { - $toDiff1 = $collection1; + if (is_array($sequence1)) { + $toDiff1 = $sequence1; } - else if (method_exists($collection1, 'toArray')) { - $toDiff1 = $collection1->toArray(); + else if (method_exists($sequence1, 'toArray')) { + $toDiff1 = $sequence1->toArray(); } else { - $toDiff1 = iterator_to_array($collection1); + $toDiff1 = iterator_to_array($sequence1); } - if (is_array($collection2)) { - $toDiff2 = $collection2; + if (is_array($sequence2)) { + $toDiff2 = $sequence2; } - else if (method_exists($collection2, 'toArray')) { - $toDiff2 = $collection2->toArray(); + else if (method_exists($sequence2, 'toArray')) { + $toDiff2 = $sequence2->toArray(); } else { - $toDiff2 = iterator_to_array($collection2); + $toDiff2 = iterator_to_array($sequence2); } return array_diff($toDiff1, $toDiff2); @@ -926,30 +926,30 @@ function diff($collection1, $collection2) /** * Computes the intersection of arrays or traversable objects * - * @param array|\Traversable $collection1 - * @param array|\Traversable $collection2 + * @param array|\Traversable $sequence1 + * @param array|\Traversable $sequence2 * @return array */ -function intersect($collection1, $collection2) +function intersect($sequence1, $sequence2) { - if (is_array($collection1)) { - $toDiff1 = $collection1; + if (is_array($sequence1)) { + $toDiff1 = $sequence1; } - else if (method_exists($collection1, 'toArray')) { - $toDiff1 = $collection1->toArray(); + else if (method_exists($sequence1, 'toArray')) { + $toDiff1 = $sequence1->toArray(); } else { - $toDiff1 = iterator_to_array($collection1); + $toDiff1 = iterator_to_array($sequence1); } - if (is_array($collection2)) { - $toDiff2 = $collection2; + if (is_array($sequence2)) { + $toDiff2 = $sequence2; } - else if (method_exists($collection2, 'toArray')) { - $toDiff2 = $collection2->toArray(); + else if (method_exists($sequence2, 'toArray')) { + $toDiff2 = $sequence2->toArray(); } else { - $toDiff2 = iterator_to_array($collection2); + $toDiff2 = iterator_to_array($sequence2); } return array_intersect($toDiff1, $toDiff2);