Updated unique docs

This commit is contained in:
Mike Farah 2022-04-29 12:16:57 +10:00
parent 1425d0720e
commit 689c535a29
4 changed files with 17 additions and 13 deletions

View File

@ -1,3 +1,4 @@
# Unique # Unique
This is used to filter out duplicated items in an array. This is used to filter out duplicated items in an array. Note that the original order of the array is maintained.

View File

@ -9,10 +9,12 @@ Note that versions prior to 4.18 require the 'eval/e' command to be specified.&#
{% endhint %} {% endhint %}
## Unique array of scalars (string/numbers) ## Unique array of scalars (string/numbers)
Note that unique maintains the original order of the array.
Given a sample.yml file of: Given a sample.yml file of:
```yaml ```yaml
- 1
- 2 - 2
- 1
- 3 - 3
- 2 - 2
``` ```
@ -22,8 +24,8 @@ yq 'unique' sample.yml
``` ```
will output will output
```yaml ```yaml
- 1
- 2 - 2
- 1
- 3 - 3
``` ```

View File

@ -7,10 +7,11 @@ import (
var uniqueOperatorScenarios = []expressionScenario{ var uniqueOperatorScenarios = []expressionScenario{
{ {
description: "Unique array of scalars (string/numbers)", description: "Unique array of scalars (string/numbers)",
document: `[1,2,3,2]`, subdescription: "Note that unique maintains the original order of the array.",
document: `[2,1,3,2]`,
expression: `unique`, expression: `unique`,
expected: []string{ expected: []string{
"D0, P[], (!!seq)::- 1\n- 2\n- 3\n", "D0, P[], (!!seq)::- 2\n- 1\n- 3\n",
}, },
}, },
{ {