Skip to main content

$$distinct

Returns a distinct array (repeating elements removed, only primitive values are supported if no by was specified)

Usage​

{ 
"$$distinct": /* Array of elements */,
"by": "##current" /* Transformer(##current) */
}
"$$distinct([by]):{input}"
note

Concrete values in the usage example are default values.

Returns​

array - Same items type as input

Arguments​

ArgumentTypeValuesRequired / Default ValueDescription
PrimaryarrayYesArray of elements
byTransformer(##current)##currentA mapping for each element to distinct by (instead of the whole element, using ##current to refer to the current item)
  • ##current - Current 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
},
{
"a": 1
}
]
{
"$$distinct": "$",
"by": "##current"
}
[
{
"a": 1
}
]
[
[
"a",
1
],
[
"a",
2
],
[
"a",
1
],
[
"a",
1
]
]
{
"$$distinct": "$",
"by": "##current"
}
[
[
"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
}
]
[
{
"a": 1
},
{
"a": 1,
"b": 1
},
{
"a": 1,
"b": 2
},
{
"a": 2,
"b": 1
}
]
{
"$$distinct": "$"
}
[
{
"a": 1
},
{
"a": 1,
"b": 1
},
{
"a": 1,
"b": 2
},
{
"a": 2,
"b": 1
}
]
[
{
"a": 1
},
{
"a": 1,
"b": 1
},
{
"a": 1,
"b": 2
},
{
"a": 2,
"b": 1
}
]
"$$distinct(##current.a):$"
[
{
"a": 1
},
{
"a": 2,
"b": 1
}
]