fsprojects / FSharp.Control.AsyncSeq

Asynchronous sequences for F#
https://fsprojects.github.io/FSharp.Control.AsyncSeq/
Other
161 stars 59 forks source link

Add AsyncSeq.head and AsyncSeq.tail #154

Open Caleb9 opened 2 years ago

Caleb9 commented 2 years ago

Hello!

Regular Seq contains simple convenience functions head and tail. I implemented those for AsyncSeq, maybe they could be added?

Thanks.

abelbraaksma commented 1 year ago

Isn't Async.head the same as Async.first, which already exists? Well, firstOrDefault exists, which is close enough, no? https://fsprojects.github.io/FSharp.Control.AsyncSeq/reference/fsharp-control-asyncseq.html#firstOrDefault

Though there's no tail. There should probably be a tail and tryTail pair, and yes, maybe it does make sense to have a head and tryHead for parity with Seq.

Caleb9 commented 1 year ago

It sure is, it's just a slight inconsistency with non-async collections API (i.e. Seq has head and tail). It's no biggie, the PR can be closed if it's not desirable to have these two APIs aligned in this way :).

abelbraaksma commented 1 year ago

FWIW, TaskSeq, which uses a resumable state machine and task from F# 6 under the hood, and implements IAsyncEnumerable<_> similar to async foreach in C#, has those functions: https://github.com/fsprojects/FSharp.Control.TaskSeq

dsyme commented 1 month ago

@abelbraaksma Should we close this old one out?