@@ -921,7 +921,7 @@ public static IAsyncEnumerable<T> Repeat<T>(this IAsyncEnumerable<T> source, lon
921921 /// <typeparam name="T">The element type.</typeparam>
922922 /// <param name="source">The source async sequence to repeatedly relay items of.</param>
923923 /// <param name="condition">The function called when the current run completes with
924- /// the current run index (zero-based) and should return to repeat the sequence once more, false to end it.</param>
924+ /// the current run index (zero-based) and should return true to repeat the sequence once more, false to end it.</param>
925925 /// <returns>The new IAsyncEnumerable instance.</returns>
926926 public static IAsyncEnumerable < T > Repeat < T > ( this IAsyncEnumerable < T > source , Func < long , bool > condition )
927927 {
@@ -930,6 +930,21 @@ public static IAsyncEnumerable<T> Repeat<T>(this IAsyncEnumerable<T> source, Fun
930930 return new Repeat < T > ( source , long . MaxValue , condition ) ;
931931 }
932932
933+ /// <summary>
934+ /// Repeatedly relay the source async sequence, once it completes the previous time, when the function returns true, ending the sequence otherwise.
935+ /// </summary>
936+ /// <typeparam name="T">The element type.</typeparam>
937+ /// <param name="source">The source async sequence to repeatedly relay items of.</param>
938+ /// <param name="condition">The function called when the current run completes with
939+ /// the current run index (zero-based) and should return a task with true to repeat the sequence once more, false to end it.</param>
940+ /// <returns>The new IAsyncEnumerable instance.</returns>
941+ public static IAsyncEnumerable < T > Repeat < T > ( this IAsyncEnumerable < T > source , Func < long , Task < bool > > condition )
942+ {
943+ RequireNonNull ( source , nameof ( source ) ) ;
944+ RequireNonNull ( condition , nameof ( condition ) ) ;
945+ return new RepeatTask < T > ( source , condition ) ;
946+ }
947+
933948 /// <summary>
934949 /// Retry a possibly failing async sequence, optionally a limited number of times before giving up.
935950 /// </summary>
@@ -957,6 +972,20 @@ public static IAsyncEnumerable<T> Retry<T>(this IAsyncEnumerable<T> source, Func
957972 return new Retry < T > ( source , long . MaxValue , condition ) ;
958973 }
959974
975+ /// <summary>
976+ /// Retry a possibly failing async sequence if the condition returns true for the Exception and/or retry index.
977+ /// </summary>
978+ /// <typeparam name="T">The element type of the source async sequence.</typeparam>
979+ /// <param name="source">The source async sequence that could fail and should be repeated.</param>
980+ /// <param name="condition">Called when the sequence fails with the retry index (zero-based) and last failure Exception and should return a task with true if the sequence should be retried.</param>
981+ /// <returns>The new IAsyncEnumerable instance.</returns>
982+ public static IAsyncEnumerable < T > Retry < T > ( this IAsyncEnumerable < T > source , Func < long , Exception , Task < bool > > condition )
983+ {
984+ RequireNonNull ( source , nameof ( source ) ) ;
985+ RequireNonNull ( condition , nameof ( condition ) ) ;
986+ return new RetryTask < T > ( source , condition ) ;
987+ }
988+
960989 /// <summary>
961990 /// Skips the last given number of items from the source
962991 /// async sequence.
@@ -1442,5 +1471,64 @@ public static IAsyncEnumerable<TResult> Replay<TSource, TResult>(this IAsyncEnum
14421471 RequireNonNull ( func , nameof ( func ) ) ;
14431472 return new Replay < TSource , TResult > ( source , func ) ;
14441473 }
1474+
1475+ /// <summary>
1476+ /// Switches to a newer source async sequence, disposing the old one,
1477+ /// when the source async sequence produces
1478+ /// a value and is mapped to an async sequence via a function.
1479+ /// </summary>
1480+ /// <typeparam name="TSource">The source value type.</typeparam>
1481+ /// <typeparam name="TResult">The result value type.</typeparam>
1482+ /// <param name="source">The source to map into async sequences and switch between them.</param>
1483+ /// <param name="mapper">The function that receives the source item and should
1484+ /// return an async sequence to be run.</param>
1485+ /// <returns>The new IAsyncEnumerable sequence.</returns>
1486+ public static IAsyncEnumerable < TResult > SwitchMap < TSource , TResult > ( this IAsyncEnumerable < TSource > source , Func < TSource , IAsyncEnumerable < TResult > > mapper )
1487+ {
1488+ RequireNonNull ( source , nameof ( source ) ) ;
1489+ RequireNonNull ( mapper , nameof ( mapper ) ) ;
1490+ return new SwitchMap < TSource , TResult > ( source , mapper ) ;
1491+ }
1492+
1493+ /// <summary>
1494+ /// Switches to a newer source async sequence, disposing the old one,
1495+ /// when the source async sequence produces a new inner async sequence.
1496+ /// </summary>
1497+ /// <typeparam name="TSource">The source value type.</typeparam>
1498+ /// <param name="sources">The async sequence of async sequences to switch between.</param>
1499+ /// <returns>The new IAsyncEnumerable sequence.</returns>
1500+ public static IAsyncEnumerable < TSource > Switch < TSource > ( this IAsyncEnumerable < IAsyncEnumerable < TSource > > sources )
1501+ {
1502+ RequireNonNull ( sources , nameof ( sources ) ) ;
1503+ return sources . SwitchMap ( v => v ) ;
1504+ }
1505+
1506+ /// <summary>
1507+ /// Runs the inner async sequences, produced by an outer async sequence,
1508+ /// one after the other and relays their items.
1509+ /// </summary>
1510+ /// <typeparam name="TSource">The value type.</typeparam>
1511+ /// <param name="sources">The async sequence of async sequences to concatenate.</param>
1512+ /// <returns>The new IAsyncEnumerable sequence.</returns>
1513+ public static IAsyncEnumerable < TSource > Concat < TSource > ( this IAsyncEnumerable < IAsyncEnumerable < TSource > > sources )
1514+ {
1515+ RequireNonNull ( sources , nameof ( sources ) ) ;
1516+ return sources . ConcatMap ( v => v ) ;
1517+ }
1518+
1519+ /// <summary>
1520+ /// Runs the inner async sequences, produced by an outer async sequence,
1521+ /// some or all concurrently and relays their items single a serialized async sequence.
1522+ /// </summary>
1523+ /// <typeparam name="TSource">The value type.</typeparam>
1524+ /// <param name="sources">The async sequence of async sequences to merge at once.</param>
1525+ /// <param name="maxConcurrency">The maximum number of inner sequences to run at once.</param>
1526+ /// <param name="prefetch">The number of items to prefetch from each inner async sequence.</param>
1527+ /// <returns>The new IAsyncEnumerable instance.</returns>
1528+ public static IAsyncEnumerable < TSource > Merge < TSource > ( this IAsyncEnumerable < IAsyncEnumerable < TSource > > sources , int maxConcurrency = int . MaxValue , int prefetch = 32 )
1529+ {
1530+ RequireNonNull ( sources , nameof ( sources ) ) ;
1531+ return sources . FlatMap ( v => v , maxConcurrency , prefetch ) ;
1532+ }
14451533 }
14461534}
0 commit comments