Skip to content

Commit

Permalink
Merge branch 'documentation'
Browse files Browse the repository at this point in the history
  • Loading branch information
ace411 committed Feb 25, 2019
2 parents c4b4255 + fcf815e commit 5664b11
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 1 deletion.
24 changes: 23 additions & 1 deletion docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@

- Added constant static function definitions for ```Monadic``` types

- Added new ```Collection``` functions

### New Helper functions

- toWords()
Expand All @@ -382,4 +384,24 @@

- filterM()

- foldM()
- foldM()

### New Collection functions

- fetch()

- contains()

- unique()

- head()

- tail()

- last()

- intersects()

- implode()

- offsetGet()
170 changes: 170 additions & 0 deletions docs/immutable-lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,176 @@ $list = Collection::from(...range(1, 10))
//outputs the collection [1, 2, 'foo', 'foo', 'foo', 6, 7, 8, 9, 10]
```

## fetch

```
$list->fetch(mixed $key)
```

**Since:** v1.12.0

**Argument(s)**

- ***key (mixed)*** - The key on which the search is based

Fetch all the values which correspond to a specified key.

```php
$collection = Collection::from(...[
['id' => 35, 'name' => 'Durant'],
['id' => 24, 'name' => 'Bryant']
]);

print_r($collection->fetch('name'));
```

## contains
```
$list->contains(mixed $value)
```

**Since:** v1.12.0

**Argument(s):**

- ***value (mixed)*** - The value whose existence is examinable

Checks if a value exists in a collection. Akin to the [key_exists](https://secure.php.net/manual/en/function.key-exists.php) function.

```php
$contains = Collection::from(...[
['id' => 3, 'name' => 'Wade'],
['id' => 23, 'name' => 'Mike']
])->contains('name'); //returns true
```

## offsetGet
```
$list->offsetGet(int $offset);
```
**Since:** v1.12.0

**Argument(s):**

- ***offset (integer)*** - The numerical key with a unique data value binding

Returns a value which corresponds to a specified numerical key.

```php
$val = Collection::from(...range(1, 5))->offsetGet(2);
//outputs 3
```

## unique
```
$list->unique();
```

**Since:** v1.12.0

**Argument(s):**

> None
Analogous to the [unique](/collection?id=unique-function) function.

```php
$list = Collection::from(...range(1, 3))
->merge(Collection::from(...range(2, 5)))
->unique();
//outputs the Collection [1, 2, 3, 4, 5]
```

## head
```
$list->head();
```

**Since:** v1.12.0

**Argument(s):**

> None
Analogous to the [head](/collection?id=head-function) function

```php
$arr = range(1, 5);
$head = Collection::from(...$arr)->head();
```

## tail
```
$list->tail();
```

**Since:** v1.12.0

**Argument(s):**

> None
Analogous to the [tail](/collection?id=tail-function) function.

```php
$tail = Collection::from(...$arr)->tail();
//outputs the Collection [2, 3, 4, 5]
```

## last
```
$list->last();
```

**Since:** v1.12.0

**Argument(s):**

> None
Analogous to the [last](/collection?id=last-function) function.

```php
$last = Collection::from(...$arr)->last(); //returns 5
```

## intersects
```
$list->intersects(Collection $list);
```

**Since:** v1.12.0

**Argument(s):**

- ***list (Collection)*** - The list to compare values with

Analogous to the [intersects](/collection?id=intersects-function) function.

```php
$intersects = Collection::from(...range(1, 3))
->intersects(Collection::from(...range(5, 7)));
//returns false
```

## implode
```
$list->implode(string $delimiter);
```

**Since:** v1.12.0

**Argument(s):**

- ***delimiter (string)*** - The string to insert between elements

Joins Collection elements with a string. Analogous to the [implode](https://secure.php.net/manual/en/function.implode.php) function.

```php
$str = Collection::from(...['Mike', 'is', 'the', 'GOAT'])->implode(' ');
//prints "Mike is the GOAT"
```

## toArray

```
Expand Down

0 comments on commit 5664b11

Please sign in to comment.