$$distinct
Returns a distinct array (repeating elements removed, only primitive values are supported if no by
is specified)
Usage​
{
"$$distinct": [ /* values */ ],
"by": /* Transformer */
}
"$$distinct([by]):{input}"
Returns​
array
(same items type as input)
Arguments​
Argument | Type | Values | Required / Default Value | Description |
---|---|---|---|---|
Primary | array | Yes | Array of elements | |
by | Transformer(##current ) | Input is ##current (current element) | "##current" | A mapping for each element to distinct by (instead of the whole element) |
Examples​
Input
Definition
Output
[
"a",
"b",
"b",
"c",
"b"
]
{
"$$distinct": "$"
}
[
"a",
"b",
"c"
]
[
"a",
1,
false,
"b",
"c",
"b",
1,
false,
false
]
{
"$$distinct": "$"
}
[
"a",
1,
false,
"b",
"c"
]
[
"a",
"a",
null,
null,
"a",
null
]
{
"$$distinct": "$"
}
[
"a",
null
]
[
{ "a": 1 },
{ "a": 1 },
{ "a": 1 }
]
{
"$$distinct": "$"
}
[
{ "a": 1 }
]
[
[ "a", 1 ],
[ "a", 2 ],
[ "a", 1 ],
[ "a", 1 ]
]
{
"$$distinct": "$"
}
[
[ "a", 1 ],
[ "a", 2 ]
]
[
{ "a": 1 },
{
"a": 1,
"b": 1
},
{ "a": 1,
"b": 2
},
{ "a": 2,
"b": 1
}
]
{
"$$distinct": "$",
"by": "##current.a"
}
[
{ "a": 1 },
{
"a": 2,
"b": 1
}
]
[
{ "a": 1 },
{
"a": 1 ,
"b": 1
},
{
"a": 1,
"b": 2
},
{
"a": 2,
"b": 1
}
]
{
"$$distinct": "$",
"by": "##current.b"
}
[
{ "a": 1 },
{
"a": 1,
"b": 1
},
{
"a": 1,
"b": 2
}
]