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 optional arguments for side_effect() #113

Merged
merged 3 commits into from
Feb 19, 2017
Merged

Conversation

bbayles
Copy link
Collaborator

@bbayles bbayles commented Feb 16, 2017

Re: PR #112, this adds some new optional keyword arguments to side_effect().

Previously the function passed in was only allowed to accept a single argument. It now must accept an item from the iterable as the first argument, and a fixed set of other arguments can be passed in. Additionally, keyword arguments can be specified.

Also added is file_obj, which is a hint that the function will operate on a file object that should be closed after iterating. See the tests, docstring, and the older PR for motivating use cases.


I could be persuaded to get rid of the argument / keyword argument and just give examples with lambdas or partials. Anybody feel strongly?

Many thanks to @yardsale8 for the suggestion.

@bbayles
Copy link
Collaborator Author

bbayles commented Feb 19, 2017

I could be persuaded to get rid of the argument / keyword argument and just give examples with lambdas or partials. Anybody feel strongly?

I persuaded myself; this PR now just adds the file_obj hint.

@bbayles bbayles merged commit 2e6f095 into master Feb 19, 2017
@bbayles bbayles deleted the side-effect-extensions branch February 19, 2017 18:26
>>> f = StringIO()
>>> func = lambda x: print(x, file=f)
>>> it = [u'a', u'b', u'c']
>>> consume(side_effect(func, it, file_obj=f))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we ought to change file_obj to file for brevity. That was going to be my only reason, but look at the print call just above: file=. So, consistency, too. :-) What do you think?

Copy link
Collaborator Author

@bbayles bbayles Feb 23, 2017

Choose a reason for hiding this comment

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

file is the name of a built-in in Python 2, otherwise I would have done that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But as a kwarg, it doesn't collide with names: it's more akin to a dictionary key.

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.

None yet

2 participants