@@ -1616,5 +1616,85 @@ public static IAsyncEnumerable<TCollection> Buffer<TSource, TOther, TCollection>
16161616 return new BufferBoundaryExact < TSource , TOther , TCollection > ( source , boundary , collectionSupplier , maxSize ) ;
16171617 }
16181618
1619+ /// <summary>
1620+ /// Checks if the source items have been seen before by checking if
1621+ /// they are already successfully added to a HashSet or not, ensuring
1622+ /// only distinct source items pass through.
1623+ /// </summary>
1624+ /// <typeparam name="TSource">The element type of the source and result.</typeparam>
1625+ /// <param name="source">The source to have distinct items only of.</param>
1626+ /// <returns>The new IAsyncEnumerable sequence.</returns>
1627+ public static IAsyncEnumerable < TSource > Distinct < TSource > ( this IAsyncEnumerable < TSource > source )
1628+ {
1629+ return Distinct ( source , v => v , ( ) => new HashSet < TSource > ( ) ) ;
1630+ }
1631+
1632+ /// <summary>
1633+ /// Checks if the source items have been seen before by checking if
1634+ /// they are already successfully added to a HashSet or not, ensuring
1635+ /// only distinct source items pass through.
1636+ /// </summary>
1637+ /// <typeparam name="TSource">The element type of the source and result.</typeparam>
1638+ /// <param name="source">The source to have distinct items only of.</param>
1639+ /// <param name="comparer">The comparer for comparing items in the HashSet</param>
1640+ /// <returns>The new IAsyncEnumerable sequence.</returns>
1641+ public static IAsyncEnumerable < TSource > Distinct < TSource > ( this IAsyncEnumerable < TSource > source , IEqualityComparer < TSource > comparer )
1642+ {
1643+ RequireNonNull ( comparer , nameof ( comparer ) ) ;
1644+ return Distinct ( source , v => v , ( ) => new HashSet < TSource > ( comparer ) ) ;
1645+ }
1646+
1647+ /// <summary>
1648+ /// Checks if the source items have been seen before by checking if
1649+ /// a key extracted from such items is in a HashSet or not, ensuring
1650+ /// only distinct source items pass through.
1651+ /// </summary>
1652+ /// <typeparam name="TSource">The element type of the source and result.</typeparam>
1653+ /// <typeparam name="TKey">The key type used for comparing items.</typeparam>
1654+ /// <param name="source">The source to have distinct items only of.</param>
1655+ /// <param name="keySelector">The function that receives the source item and should return a key value for distinct comparison.</param>
1656+ /// <returns>The new IAsyncEnumerable sequence.</returns>
1657+ public static IAsyncEnumerable < TSource > Distinct < TSource , TKey > ( this IAsyncEnumerable < TSource > source , Func < TSource , TKey > keySelector )
1658+ {
1659+ return Distinct ( source , keySelector , ( ) => new HashSet < TKey > ( ) ) ;
1660+ }
1661+
1662+ /// <summary>
1663+ /// Checks if the source items have been seen before by checking if
1664+ /// a key extracted from such items is in a HashSet or not, ensuring
1665+ /// only distinct source items pass through.
1666+ /// </summary>
1667+ /// <typeparam name="TSource">The element type of the source and result.</typeparam>
1668+ /// <typeparam name="TKey">The key type used for comparing items.</typeparam>
1669+ /// <param name="source">The source to have distinct items only of.</param>
1670+ /// <param name="keySelector">The function that receives the source item and should return a key value for distinct comparison.</param>
1671+ /// <param name="keyComparer">The comparer for comparing keys in the HashSet</param>
1672+ /// <returns>The new IAsyncEnumerable sequence.</returns>
1673+ public static IAsyncEnumerable < TSource > Distinct < TSource , TKey > ( this IAsyncEnumerable < TSource > source , Func < TSource , TKey > keySelector , IEqualityComparer < TKey > keyComparer )
1674+ {
1675+ RequireNonNull ( keyComparer , nameof ( keyComparer ) ) ;
1676+ return Distinct ( source , keySelector , ( ) => new HashSet < TKey > ( keyComparer ) ) ;
1677+ }
1678+
1679+ /// <summary>
1680+ /// Checks if the source items have been seen before by checking
1681+ /// a key extracted from such items agains a set of keys and
1682+ /// drops such items, ensuring that only distinct source items pass
1683+ /// through.
1684+ /// </summary>
1685+ /// <typeparam name="TSource">The element type of the source and result.</typeparam>
1686+ /// <typeparam name="TKey">The key type used for comparing items.</typeparam>
1687+ /// <param name="source">The source to have distinct items only of.</param>
1688+ /// <param name="keySelector">The function that receives the source item and should return a key value for distinct comparison.</param>
1689+ /// <param name="setSupplier">The function that should provide a set implementation whose <see cref="ISet{T}.Add(T)"/> method's return
1690+ /// value decided is the source item should pass or not.</param>
1691+ /// <returns>The new IAsyncEnumerable sequence</returns>
1692+ public static IAsyncEnumerable < TSource > Distinct < TSource , TKey > ( this IAsyncEnumerable < TSource > source , Func < TSource , TKey > keySelector , Func < ISet < TKey > > setSupplier )
1693+ {
1694+ RequireNonNull ( source , nameof ( source ) ) ;
1695+ RequireNonNull ( keySelector , nameof ( keySelector ) ) ;
1696+ RequireNonNull ( setSupplier , nameof ( setSupplier ) ) ;
1697+ return new Distinct < TSource , TKey > ( source , keySelector , setSupplier ) ;
1698+ }
16191699 }
16201700}
0 commit comments