Skip to content

Commit

Permalink
Replace unique with unique_by in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dpolac committed May 11, 2016
1 parent 28f0fc7 commit 4cc32db
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Listing names of all authors ordered by age:
```twig
{% for author in articles|map(=> _.author)|unique|sort_by(=> _.age) %}
{% for author in articles|map(=> _.author)|unique_by('===')|sort_by(=> _.age) %}
* {{ author.name }}, {{ author.age }}
{% endfor %}
```
Expand Down Expand Up @@ -111,11 +111,29 @@ Returns array of elements that passes a test specified by lambda.

----------------------------------------------------------------

<a name="unique"></a>
### |unique
**Signature:** `array|unique`
<a name="unique_by"></a>
### |unique_by
**Signature:** `array|unique_by(lambda|'==='|'==')`

Returns array of unique elements. Uniqueness is checked with
passed lambda. PHP operators == or === will be used if
string '==' or '===' is passed instead of lambda.

Lambda should have two arguments - items to check. Keys of
elements are also passed as third and fourth argument.

```twig
{% for i in [1, 2, 2, 3, 1]|unique_by((i1;i2) => i1 == i2) %}
{{ i }} {# prints '1 2 3' #}
{% endfor %}
```
equivalent
```twig
{% for i in [1, 2, 2, 3, 1]|unique_by('==') %}
{{ i }} {# prints '1 2 3' #}
{% endfor %}
```

Returns array with every element occurring only once.

----------------------------------------------------------------

Expand Down

0 comments on commit 4cc32db

Please sign in to comment.