Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
aadegbam authored and aadegbam committed May 7, 2018
1 parent ada796c commit f2a2204
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit f2a2204

Please sign in to comment.