-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggest to add a chunkBy
function (to group and yield adjacent items sharing the same key) to the library
#156
Comments
@natalie-o-perret Looks good, please consider making a PR, thanks |
You may want to take a close look at what happens if multiple threads are iterating with the resulting sequence. I think the code can cause race conditions. There are functions in this library that specifically warn about that, so maybe it’s enough to just say so in the doc comments. I’m currently considering adding the same to |
This is a good point 🤔. |
@natalie-o-perret I’m not sure about My concern with AsyncSeq is that there’s a much larger chance it’s used in multi threaded scenarios. Not entirely sure what the base premise is with sharing enumerators. While that’s generally code smell, I think this lib ought to be safe in that regard, but I’d have to check. @dsyme is there a general idea/consensus in the dotnet ecosystem that sequences should be thread safe, but enumerators of these sequences are not (or: aren’t guaranteed to be)? It waa my understanding that most collections are safe for reading, but not safe for writing. The thing is, in these functions like |
Description
Bumped into this at work the other day, and thought this could be a nice addition to the library (unless it's already part of it under another name which wouldn't be too surprising since I'm pretty good at missing out the very obvious).
Basically the idea would be to add a
chunkBy
function to theAsyncSeq
module that allows to group and yield adjacent items sharing the same key in the gist of what has been done forSeq.chunkBy
in the F#+ library here, i.e.:A naive impl., ahem translation of above I ended up with:
I've checked a bunch of
Seq
more functional approaches which seem to require more allocations: https://stackoverflow.com/a/38495042/4636721And here is a working example:
Sample output:
(Also, I know [random] vertical alignment is dumb but I can't help it)
Wdyt?
Do you think this feature is worthy-enough🔨⚡ (or just relevant 🤔) to be part of the library?
The text was updated successfully, but these errors were encountered: