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
I see chunkBySize is supposed to be added. Is there any guidance or reference for patching this in myself? I've come across a use for it in a pipeline.
This code seems to work, but I feel like it could be simplified.
letchunkBySize chunkSize (source:TaskSeq<_>)=letenumerator= source.GetAsyncEnumerator()letcheckChunkIndexAndMoveNextAsync chunkIndex =if chunkIndex < chunkSize then
enumerator.MoveNextAsync()else
ValueTask.False
taskSeq {letnextChunk()=
taskSeq {letres= Array.zeroCreate chunkSize
res[0]<- enumerator.Current
let mutablei=1while!(checkChunkIndexAndMoveNextAsync i)doletcurrent= enumerator.Current
res[i]<- current
i <- i +1if i = chunkSize then
res
else
Array.sub res 0 i
}while! enumerator.MoveNextAsync()doyield! nextChunk()}
Hey @BrianVallelunga, thanks for reporting this! Indeed, chunkBySize was (and is) on the list of functions to be added from the Seq.xxx functions (i.e., where we try to have the same surface area as F#'s Seq as we can), but we didn't yet get to it (no green checkmark in the overview, sorry).
Your code is not wrong per se. But you'd want to put the let enumerator = source.GetAsyncEnumerator() inside the taskSeq and use use, not let (this will only work in taskSeq or task, outside it, the use is not recognized). Otherwise, the lifecycle of the enumerator is not guarded by the taskSeq CE and this may lead to unwanted side effects.
You can also add a finalize by hand.
I'll add this function soon(ish). I may have some time for it this weekend, but it's been a bit busy lately.
Activity
BrianVallelunga commentedon Jun 19, 2024
This code seems to work, but I feel like it could be simplified.
abelbraaksma commentedon Jul 10, 2024
Hey @BrianVallelunga, thanks for reporting this! Indeed,
chunkBySizewas (and is) on the list of functions to be added from theSeq.xxxfunctions (i.e., where we try to have the same surface area as F#'sSeqas we can), but we didn't yet get to it (no green checkmark in the overview, sorry).Your code is not wrong per se. But you'd want to put the
let enumerator = source.GetAsyncEnumerator()inside thetaskSeqand useuse, notlet(this will only work intaskSeqortask, outside it, theuseis not recognized). Otherwise, the lifecycle of the enumerator is not guarded by thetaskSeqCE and this may lead to unwanted side effects.You can also add a
finalizeby hand.I'll add this function soon(ish). I may have some time for it this weekend, but it's been a bit busy lately.
feat: add TaskSeq.chunkBySize and TaskSeq.windowed (closes #258, ref #…
Merge pull request #303 from fsprojects/repo-assist/feat-windowed-chu…