diff --git a/src/collections_me.c b/src/collections_me.c index a0dc675..5dd8abd 100644 --- a/src/collections_me.c +++ b/src/collections_me.c @@ -178,25 +178,18 @@ const zend_function_entry collection_methods[] = { PHP_ME(Collection, minBy, selector_flags_arginfo, ZEND_ACC_PUBLIC) PHP_ME(Collection, minWith, comparator_arginfo, ZEND_ACC_PUBLIC) PHP_ME(Collection, minus, elements_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(Collection, minusAssign, elements_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(Collection, minusKeys, keys_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(Collection, minusKeysAssign, keys_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(Collection, minusValues, elements_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(Collection, minusValuesAssign, elements_arginfo, ZEND_ACC_PUBLIC) PHP_ME(Collection, none, predicate_arginfo, ZEND_ACC_PUBLIC) PHP_ME(Collection, onEach, action_arginfo, ZEND_ACC_PUBLIC) PHP_ME(Collection, packed, NULL, ZEND_ACC_PUBLIC) PHP_ME(Collection, partition, predicate_arginfo, ZEND_ACC_PUBLIC) PHP_ME(Collection, plus, elements_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(Collection, plusAssign, elements_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(Collection, plusValues, elements_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(Collection, plusValuesAssign, elements_arginfo, ZEND_ACC_PUBLIC) PHP_ME(Collection, putAll, elements_arginfo, ZEND_ACC_PUBLIC) PHP_ME(Collection, reduce, operation_arginfo, ZEND_ACC_PUBLIC) PHP_ME(Collection, reduceRight, operation_arginfo, ZEND_ACC_PUBLIC) PHP_ME(Collection, remove, key_value_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(Collection, removeAll, predicate_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(Collection, retainAll, predicate_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(Collection, removeAll, other_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(Collection, removeWhile, predicate_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(Collection, retainAll, other_arginfo, ZEND_ACC_PUBLIC) PHP_ME(Collection, reverse, NULL, ZEND_ACC_PUBLIC) PHP_ME(Collection, reversed, NULL, ZEND_ACC_PUBLIC) PHP_ME(Collection, shuffle, NULL, ZEND_ACC_PUBLIC) diff --git a/src/collections_methods.c b/src/collections_methods.c index a54203c..3af1107 100644 --- a/src/collections_methods.c +++ b/src/collections_methods.c @@ -1950,31 +1950,6 @@ PHP_METHOD(Collection, minus) } -PHP_METHOD(Collection, minusAssign) -{ - -} - -PHP_METHOD(Collection, minusKeys) -{ - -} - -PHP_METHOD(Collection, minusKeysAssign) -{ - -} - -PHP_METHOD(Collection, minusValues) -{ - -} - -PHP_METHOD(Collection, minusValuesAssign) -{ - -} - PHP_METHOD(Collection, none) { zend_fcall_info fci; @@ -2056,21 +2031,6 @@ PHP_METHOD(Collection, plus) } -PHP_METHOD(Collection, plusAssign) -{ - -} - -PHP_METHOD(Collection, plusValues) -{ - -} - -PHP_METHOD(Collection, plusValuesAssign) -{ - -} - PHP_METHOD(Collection, putAll) { zval* elements; @@ -2207,6 +2167,11 @@ PHP_METHOD(Collection, remove) } PHP_METHOD(Collection, removeAll) +{ + +} + +PHP_METHOD(Collection, removeWhile) { zend_fcall_info fci; zend_fcall_info_cache fcc; @@ -2216,10 +2181,6 @@ PHP_METHOD(Collection, removeAll) ZEND_PARSE_PARAMETERS_END(); zend_array* current = COLLECTION_FETCH_CURRENT(); SEPARATE_CURRENT_COLLECTION(current); - if (EX_NUM_ARGS() == 0) { - zend_hash_clean(current); - return; - } INIT_FCI(&fci, 2); ZEND_HASH_FOREACH_BUCKET(current, Bucket* bucket) CALLBACK_KEYVAL_INVOKE(params, bucket); @@ -2232,21 +2193,7 @@ PHP_METHOD(Collection, removeAll) PHP_METHOD(Collection, retainAll) { - zend_fcall_info fci; - zend_fcall_info_cache fcc; - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_FUNC(fci, fcc) - ZEND_PARSE_PARAMETERS_END(); - zend_array* current = COLLECTION_FETCH_CURRENT(); - SEPARATE_CURRENT_COLLECTION(current); - INIT_FCI(&fci, 2); - ZEND_HASH_FOREACH_BUCKET(current, Bucket* bucket) - CALLBACK_KEYVAL_INVOKE(params, bucket); - if (!zend_is_true(&retval)) { - zend_hash_del_bucket(current, bucket); - } - zval_ptr_dtor(&retval); - ZEND_HASH_FOREACH_END(); + } PHP_METHOD(Collection, reverse) diff --git a/src/php_collections_me.h b/src/php_collections_me.h index 134738b..efa9840 100644 --- a/src/php_collections_me.h +++ b/src/php_collections_me.h @@ -66,24 +66,17 @@ PHP_METHOD(Collection, min); PHP_METHOD(Collection, minBy); PHP_METHOD(Collection, minWith); PHP_METHOD(Collection, minus); -PHP_METHOD(Collection, minusAssign); -PHP_METHOD(Collection, minusKeys); -PHP_METHOD(Collection, minusKeysAssign); -PHP_METHOD(Collection, minusValues); -PHP_METHOD(Collection, minusValuesAssign); PHP_METHOD(Collection, none); PHP_METHOD(Collection, onEach); PHP_METHOD(Collection, packed); PHP_METHOD(Collection, partition); PHP_METHOD(Collection, plus); -PHP_METHOD(Collection, plusAssign); -PHP_METHOD(Collection, plusValues); -PHP_METHOD(Collection, plusValuesAssign); PHP_METHOD(Collection, putAll); PHP_METHOD(Collection, reduce); PHP_METHOD(Collection, reduceRight); PHP_METHOD(Collection, remove); PHP_METHOD(Collection, removeAll); +PHP_METHOD(Collection, removeWhile); PHP_METHOD(Collection, retainAll); PHP_METHOD(Collection, reverse); PHP_METHOD(Collection, reversed); diff --git a/stubs/Collection.php b/stubs/Collection.php index ffc248e..72f4da1 100644 --- a/stubs/Collection.php +++ b/stubs/Collection.php @@ -539,49 +539,6 @@ class Collection implements ArrayAccess, Countable */ function minus($elements) {} - /** - * Removes all key-value pairs contained in the given collection from this collection. - * - * @param array|Collection $elements - * @return void - */ - function minusAssign($elements) {} - - /** - * Returns a collection containing all entries of the original collection except those entries - * the keys of which are contained in the given keys collection. - * - * @param array|Collection $keys - * @return Collection - */ - function minusKeys($keys) {} - - /** - * Removes all entries the keys of which are contained in the given keys collection from this - * collection. - * - * @param array|Collection $keys - * @return void - */ - function minusKeysAssign($keys) {} - - /** - * Returns a list containing all elements of the original collection except the elements contained - * in the given elements collection. - * - * @param array|Collection $elements - * @return Collection - */ - function minusValues($elements) {} - - /** - * Removes all elements contained in the given elements collection from this collection. - * - * @param array|Collection $elements - * @return void - */ - function minusValuesAssign($elements) {} - /** * Returns true if no elements match the given predicate. * @@ -648,39 +605,13 @@ class Collection implements ArrayAccess, Countable function partition($predicate) {} /** - * Creates a new collection by replacing or adding entries to this collection from a given - * collection of key-value pairs. + * Creates a new collection by replacing or elements to this collection from a given collection. * * @param array|Collection $elements * @return Collection */ function plus($elements) {} - /** - * Appends or replaces all pairs from the given collection of pairs in this collection. - * - * @param array|Collection $elements - * @return void - */ - function plusAssign($elements) {} - - /** - * Returns a collection containing all elements of the original collection and then all elements - * of the given elements collection. - * - * @param array|Collection $elements - * @return Collection - */ - function plusValues($elements) {} - - /** - * Adds all elements of the given elements collection to this collection. - * - * @param array|Collection $elements - * @return void - */ - function plusValuesAssign($elements) {} - /** * Puts all the elements of the given collection into this collection. * @@ -717,21 +648,28 @@ class Collection implements ArrayAccess, Countable function remove($key, $value) {} /** - * Removes all elements from this collection that match the given predicate. If predicate is not - * provided, all elements will be removed. + * Removes elements of this collection whose values exists in the given collection. * - * @param callable $predicate[optional] ($value, $key) -> bool + * @param array|Collection $elements[optional] * @return void */ - function removeAll($predicate) {} + function removeAll($elements) {} /** - * Retains only elements of this collection that match the given predicate. + * Removes all elements from this collection that match the given predicate. * * @param callable $predicate ($value, $key) -> bool * @return void */ - function retainAll($predicate) {} + function removeWhile($predicate) {} + + /** + * Retains elements of this collection whose values exists in the given collection. + * + * @param array|Collection $elements + * @return void + */ + function retainAll($elements) {} /** * Reverses elements in the collection in-place. diff --git a/tests/029-remove-retain-all.phpt b/tests/029-remove-retain-all.phpt deleted file mode 100644 index 64e5566..0000000 --- a/tests/029-remove-retain-all.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -Test Collection::removeAll() and Collection::retainAll(). ---FILE-- - 4, 'b' => 1, 'c' => 9, 'd' => -2, 'e' => 0]; -$pred_is_odd = function ($value) { - return $value % 2; -}; -$collection = Collection::init($array); -$collection->removeAll($pred_is_odd); -if ($collection->toArray() != ['a' => 4, 'd' => -2, 'e' => 0]) { - echo 'Collection::removeAll() failed.', PHP_EOL; -} -$collection->removeAll(); -if ($collection->toArray() != []) { - echo 'Collection::removeAll() failed.', PHP_EOL; -} -$collection = Collection::init($array); -$collection->retainAll($pred_is_odd); -if ($collection->toArray() != ['b' => 1, 'c' => 9]) { - echo 'Collection::retainAll() failed.', PHP_EOL; -} -?> ---EXPECT-- diff --git a/tests/029-remove-while.phpt b/tests/029-remove-while.phpt new file mode 100644 index 0000000..5593776 --- /dev/null +++ b/tests/029-remove-while.phpt @@ -0,0 +1,15 @@ +--TEST-- +Test Collection::removeWhile(). +--FILE-- + 4, 'b' => 1, 'c' => 9, 'd' => -2, 'e' => 0]; +$pred_is_odd = function ($value) { + return $value % 2; +}; +$collection = Collection::init($array); +$collection->removeWhile($pred_is_odd); +if ($collection->toArray() != ['a' => 4, 'd' => -2, 'e' => 0]) { + echo 'Collection::removeWhile() failed.', PHP_EOL; +} +?> +--EXPECT--