You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would the maintainers consider including the following two helpers:
We already have AsyncSeq.init and AsyncSeq.unfoldAsync to generate new AsyncSeq, but I could not find any helper to create one from an
existing sequence of asynchronous computations (seq<Async<_>>).
The following helper ofSeqAsync would help with that:
moduleAsyncSeq =letofSeqAsync(s:seq<Async<'t>>):AsyncSeq<'t>=
asyncSeq {for asyncElement in s dolet!v= asyncElement
yield v
}
Using AsyncSeq.concatSeq, it's currently possible to concatenate sequences of AsyncSeq (as in seq<AsyncSeq<_>>) but not an AsyncSeq of AsyncSeqs.
I propose adding the following function.
moduleAsyncSeq =letconcat(s:AsyncSeq<AsyncSeq<'t>>):AsyncSeq<'t>=
asyncSeq {for innerSeq in s dofor e in innerSeq doyield e
}
Example use case
Suppose you are given:
enumerateFiles : string -> Async<AsyncSeq<string>> that asynchronously returns
an asynchronous enumeration of all files under a given directory;
and enumerateDirectories : string -> AsyncSeq<string> that
asynchronously enumerates all sub-directories under a given directory;
and you want to enumerate all files under all directories under c:\
then with the two helpers you could write it as follows:
I undertand that the function AsyncSeq.mergeAll could be used to achieve the same goal, except that it would require first enumerating all directories and convert them into a list, before doing the concatenation.
Or perhaps there is a better way to do this?
The text was updated successfully, but these errors were encountered:
Description
Would the maintainers consider including the following two helpers:
AsyncSeq.init
andAsyncSeq.unfoldAsync
to generate newAsyncSeq
, but I could not find any helper to create one from anexisting sequence of asynchronous computations (
seq<Async<_>>
).The following helper
ofSeqAsync
would help with that:AsyncSeq.concatSeq
, it's currently possible to concatenate sequences ofAsyncSeq
(as inseq<AsyncSeq<_>>
) but not anAsyncSeq
ofAsyncSeqs
.I propose adding the following function.
Example use case
Suppose you are given:
enumerateFiles : string -> Async<AsyncSeq<string>>
that asynchronously returnsan asynchronous enumeration of all files under a given directory;
enumerateDirectories : string -> AsyncSeq<string>
thatasynchronously enumerates all sub-directories under a given directory;
and you want to enumerate all files under all directories under
c:\
then with the two helpers you could write it as follows:
I undertand that the function
AsyncSeq.mergeAll
could be used to achieve the same goal, except that it would require first enumerating all directories and convert them into a list, before doing the concatenation.Or perhaps there is a better way to do this?
The text was updated successfully, but these errors were encountered: