Skip to content
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

Add 'skipMany' to skip values without needing to build an intermediat… #94

Merged
merged 2 commits into from Feb 3, 2017

Conversation

Projects
None yet
3 participants
@merijn
Copy link
Contributor

merijn commented Jan 19, 2017

I often find myself needing to skip over many tags while scraping messy data. Having a convenient combinator for this is nicer than repeated use of 'manyIgnoreYield (return Nothing)', although not absolutely crucial.

skipMany :: MonadThrow m
=> Consumer Event m (Maybe a)
-> Consumer Event m ()
skipMany consumer = manyIgnoreYield (return Nothing) ((() <$) <$> consumer)

This comment has been minimized.

Copy link
@snoyberg

snoyberg Jan 24, 2017

Owner

Is () <$ the same as void?

This comment has been minimized.

Copy link
@merijn

merijn Jan 24, 2017

Author Contributor

Yes, I think I initially tried () <$ which doesn't map inside the Maybe and didn't think of using void when changing is, I've changed that now.

@k0ral

This comment has been minimized.

Copy link
Collaborator

k0ral commented Feb 3, 2017

How does skipMany differ (in behavior or in memory usage) from void . many ?

@merijn

This comment has been minimized.

Copy link
Contributor Author

merijn commented Feb 3, 2017

void . many builds up an intermediate list which is then discarded. Whereas this builds up no intermediate list, as a result this consumes O(1) space, vs O(n) for void . many, similar to the reason for sequence_ existing in addition to sequence. This function would also be nice for cleaning up the issue with takeAllTreesContent mentioned in the other PR.

@merijn

This comment has been minimized.

Copy link
Contributor Author

merijn commented Feb 3, 2017

Actually, many_ might be a better name (similar to sequence and sequence_) as this doesn't really "skip" anything per se (since the actions are still run)...

@k0ral k0ral merged commit bb17fed into snoyberg:master Feb 3, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@k0ral

This comment has been minimized.

Copy link
Collaborator

k0ral commented Feb 3, 2017

Merged and renamed into many_. Thank you ! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.