fsprojects / FSharp.Control.TaskSeq

A computation expression and module for seamless working with IAsyncEnumerable<'T> as if it is just another sequence
MIT License
93 stars 8 forks source link

Implement `take`, `truncate`, `skip` and `drop` #209

Closed abelbraaksma closed 10 months ago

abelbraaksma commented 10 months ago

This fixes part of #208, the following signatures are added and implemented (todo: tests)

static member skip: count: int -> source: TaskSeq<'T> -> TaskSeq<'T>
static member drop: count: int -> source: TaskSeq<'T> -> TaskSeq<'T>
static member take: count: int -> source: TaskSeq<'T> -> TaskSeq<'T>
static member truncate: count: int -> source: TaskSeq<'T> -> TaskSeq<'T>

Note that skip and take raise if there are not enough elements (just like its Seq counterparts) and that truncate and drop do not raise. While drop does not exist in Seq, I felt it make sense as truncate also exists. Maybe it can be added to F# Core?

PS, in case anybody wondered, I chose the name drop simply because it exists in Scala. I'm not a fan of Scala per se, but was just looking for existing functions that behave like this one, and indeed, the Scala function does not raise either.

See also discussion here: https://stackoverflow.com/questions/1247788/calling-seq-skip-and-seq-take-in-f

TODO list:

abelbraaksma commented 10 months ago

This is ready, now that the obvious errors are fixed ;)

abelbraaksma commented 10 months ago

Added .fantomasignore in two places (needed for VS 2022 plugin to work). This fixes a (temporary) bug in Fantomas that raises an error because of WhileBang, see https://github.com/fsprojects/fantomas/issues/3019

abelbraaksma commented 10 months ago

Thanks for the review, @bartelink. I'll merge this in as soon as it passes the tests.

abelbraaksma commented 10 months ago

I sorted out the issue with the test reports not showing. Reported here: https://github.com/dorny/test-reporter/issues/343 (see my comments). See also this thread: https://github.com/actions/upload-artifact/issues/472