From f2a22046aef186043e025a1ca17e8e42efc73b36 Mon Sep 17 00:00:00 2001 From: aadegbam Date: Mon, 7 May 2018 15:22:55 -0600 Subject: [PATCH] Documentation --- docs/QUICKSTART.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/QUICKSTART.md b/docs/QUICKSTART.md index 2dbc871..11699a8 100644 --- a/docs/QUICKSTART.md +++ b/docs/QUICKSTART.md @@ -31,6 +31,12 @@ $generic_collection_with_items = new \VersatileCollections\GenericCollection(...$items); ``` +> Note that the constructors for all collection classes use the variadic function signature. +Therefore if you want to pass an array of items to the constructor you have to use the +argument unpacking syntax (like in the last example above) or you could call the `static` +method `\VersatileCollections\CollectionInterface::makeNewCollection(array $items=[])` which +can accept an array of items without the need for argument unpacking. + When collections are created with items (like in the last two examples above), the collection is in list mode (i.e. the keys for each item in the newly created collection are sequential-numeric keys.) For example: @@ -502,6 +508,12 @@ To check if a key exists in the collection, you can call `isset` like so: } } ``` +* **`makeNewCollection(array $items=[])`:** A static factory method for creating new collection objects from an array of items. Using this method eliminates the need for argument unpacking which is required by all collection constructors when you try to create new collection objects from an array of items. + ```php + $items = ['item 1', 'item 2', 'item 3', 'item 4']; + $generic_collection_with_items = + \VersatileCollections\GenericCollection::makeNewCollection($items); + ``` * **`merge(CollectionInterface $other)`:** Adds all items from $other collection to $this collection. Items in $other with existing keys in $this will overwrite the existing items in $this. ```php $numeric_collection = new \VersatileCollections\NumericsCollection(