Skip to content

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

Merged
k0ral merged 2 commits intosnoyberg:masterfrom
merijn:skipmany
Feb 3, 2017
Merged

Add 'skipMany' to skip values without needing to build an intermediat…#94
k0ral merged 2 commits intosnoyberg:masterfrom
merijn:skipmany

Conversation

@merijn
Copy link
Copy Markdown
Contributor

@merijn 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)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is () <$ the same as void?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator

k0ral commented Feb 3, 2017

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

@merijn
Copy link
Copy Markdown
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
Copy link
Copy Markdown
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
@k0ral
Copy link
Copy Markdown
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants