-
Notifications
You must be signed in to change notification settings - Fork 29k
Fix python typo #4840
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
Fix python typo #4840
Conversation
|
Can one of the admins verify this patch? |
docs/programming-guide.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clearly this has to change. I don't know much Python so would be interested to hear the answer myself: is it certain that acc.add(x) evaluates to true so that f(x) is always evaluated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like acc.add(x) will always evaluate to None [1], so the function will never evaluate f(x). A hacky way to fix this may be to change the lambda to
lambda x: not acc.add(x) and f(x)because not None evaluates to True, but this certainly won't make things more clear for the reader. The best fix would be do define a separate function
def g(x):
acc.add(x)
return f(x)
data.map(g)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the separate function; there really is no good way to write multi-line lambdas in Python.
|
@srowen What do you think of this? |
|
Certainly looks like something that stands a change of working, and approved by @laserson. I'll wait a little for any other comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine, but if you want a crazy one-liner:
data.map(lambda x: (acc.add(x), f(x))[1])
Don't do that at home, though. We already have Perl for that kind of shenanigans.
|
Nice catch, LGTM, thanks! |
|
Oh I realized the variable name is |
|
@srowen Good catch, I saw that, then forget it immediately, really need to take a rest.. |
|
Heh, actually the Scala and Java examples are wrong too. They should be respectively: ... and I can port the spelling fix to their comments too. |
No description provided.