Open
Conversation
DzyubSpirit
suggested changes
Feb 10, 2021
Comment on lines
+4
to
+5
| def create_log(base): | ||
| def log(n): |
There was a problem hiding this comment.
More direct translation would use lambdas here.
def translates as function in JavaScript
| @@ -0,0 +1,14 @@ | |||
|
|
|||
There was a problem hiding this comment.
Is that a PEP requirement to have an empty line in the beginning of the file if there are no comments and imports?
Comment on lines
+2
to
+6
| def partial(fn, x): | ||
| return lambda *args: fn(x, *args) | ||
|
|
||
|
|
||
| def summary(a, b, c, d): |
There was a problem hiding this comment.
ditto, lambdas would more direct translation
| return lambda *rest: fn(*(args + rest)) | ||
|
|
||
|
|
||
| def summary(a, b, c, d): |
There was a problem hiding this comment.
Let's use the same identifacators names so a person learning different languages would have easier time understanding the analogy between JavaScript and Python
Suggested change
| def summary(a, b, c, d): | |
| def sum4(a, b, c, d): |
Comment on lines
+11
to
+17
| f1 = partial(summary, 1) | ||
| f2 = partial(f1, 2) | ||
| f3 = partial(f2, 3) | ||
| print(f3(4)) | ||
|
|
||
| f11 = partial(summary, 1, 2) | ||
| f12 = partial(f11, 3) |
There was a problem hiding this comment.
ditto, let's use the same variable names
Comment on lines
+2
to
+10
| def curry(fn, *args, **kwargs): | ||
| def wrapper(*iargs, **ikwargs): | ||
| all_args = args + iargs | ||
| all_kwargs = {**kwargs, **ikwargs} | ||
| try: | ||
| return fn(*all_args, **all_kwargs) | ||
| except TypeError: | ||
| return curry(fn, *all_args, **all_kwargs) | ||
| return wrapper |
There was a problem hiding this comment.
That's cool: quite nice solution for kwargs 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.