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 python examples #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danil-topchiy
Copy link

No description provided.

Comment on lines +4 to +5
def create_log(base):
def log(n):

Choose a reason for hiding this comment

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

More direct translation would use lambdas here.
def translates as function in JavaScript

@@ -0,0 +1,14 @@

Choose a reason for hiding this comment

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

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):

Choose a reason for hiding this comment

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

ditto, lambdas would more direct translation

return lambda *rest: fn(*(args + rest))


def summary(a, b, c, d):

Choose a reason for hiding this comment

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

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)

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

That's cool: quite nice solution for kwargs 👍

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.

2 participants