I often need to perform LinQ queries to get distinct items from a IEnumerable based on one of its properties. I would like to know if this is a good way to wrap this operation:
<Extension()> Function DistinctOn(Of T)(iet As IEnumerable(Of T), identity_property As Func(Of T, Object) ) As IEnumerable(Of T) Return iet.GroupBy(identity_property).Select(Function(g) g.First) End Function
Using example (
pastas is a IEnumerable of
Dim dpastas = pastas.DistinctOn(Function(jo) jo.Value(Of Integer)("id")).ToArray
It works Ok, but I'd like to know if it is good code also. Thank you very much!