FSharp.Control.AsyncSeq icon indicating copy to clipboard operation
FSharp.Control.AsyncSeq copied to clipboard

Add AsyncSeq.head and AsyncSeq.tail

Open Caleb9 opened this issue 3 years ago • 5 comments

Hello!

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

Thanks.

Caleb9 avatar Jul 21 '22 16:07 Caleb9

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.

abelbraaksma avatar Nov 04 '22 11:11 abelbraaksma

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 :).

Caleb9 avatar Nov 07 '22 15:11 Caleb9

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

abelbraaksma avatar Nov 07 '22 15:11 abelbraaksma

@abelbraaksma Should we close this old one out?

dsyme avatar Aug 21 '24 18:08 dsyme