Skip to content

Currying - #488

Open
diogoosz wants to merge 1 commit into
javascript-tutorial:masterfrom
diogoosz:translate-currying
Open

diogoosz wants to merge 1 commit into
javascript-tutorial:masterfrom
diogoosz:translate-currying

Conversation

@diogoosz

@diogoosz diogoosz commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Tradução do artigo "Currying" para o português.

Conforme comentado na #1.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- When it is called like `curriedSum(1)`, the argument is saved in the Lexical Environment, and a new wrapper is returned `function(b)`.
- Then this wrapper is called with `2` as an argument, and it passes the call to the original `sum`.
- O resultado de `curry(func)` é um invólucro `function(a)`.
- Quando ele é chamado como `curriedSum(1)`, o argumento é salvo no Ambiente Léxico, e um novo invólucro é retornado, `function(b)`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Terminologia inconsistente: "Ambiente Léxico" aqui, mas o repo já usa "Ambiente Lexical" (ex.: 1-js/06-advanced-functions/07-new-function/article.md, linhas 49/51/123). Leitores que seguem o link mental para info:closure vão ver dois termos para o mesmo conceito. Sugestão: "Ambiente Lexical".


1. If passed `args` count is the same or more than the original function has in its definition (`func.length`) , then just pass the call to it using `func.apply`.
2. Otherwise, get a partial: we don't call `func` just yet. Instead, another wrapper is returned, that will re-apply `curried` providing previous arguments together with the new ones.
1. Se a quantidade de `args` passados for igual ou maior do que a função original tem na sua definição (`func.length`), então só passa a chamada pra ela usando `func.apply`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"igual ou maior do que a função original tem na sua definição" — comparação quebrada: falta o objeto ("do que a quantidade que a função original tem..."). Além disso, "então só passa a chamada" soa como imperativo/coloquial; sugestão: "então simplesmente repassa a chamada para ela usando func.apply".

```

Now we can easily make a convenience function for current logs:
Agora podemos facilmente fazer uma função de conveniência para os logs atuais:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"logs atuais" muda o sentido: o original "current logs" = logs com a data/hora atual (o logNow fixa new Date()). "Logs atuais" lê-se como "os logs existentes agora". Sugestão: "logs com a hora atual" (idem na linha 100: "logs de debug com a hora atual").

```

When we run it, there are two `if` execution branches:
Quando rodamos ela, existem duas ramificações de execução do `if`:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"Quando rodamos ela" — pronome reto como objeto direto; em texto didático prefira "Quando a executamos" (padrão do resto do tutorial).

O currying exige que a função tenha um número fixo de argumentos.

A function that uses rest parameters, such as `f(...args)`, can't be curried this way.
Uma função que usa parâmetros rest, como `f(...args)`, não pode ter o currying feito dessa forma.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"não pode ter o currying feito dessa forma" é construção truncada/não idiomática. Sugestão: "não pode passar por currying dessa forma" ou "não pode ser "curryficada" dessa forma".

Por definição, o currying deveria converter `sum(a, b, c)` em `sum(a)(b)(c)`.

But most implementations of currying in JavaScript are advanced, as described: they also keep the function callable in the multi-argument variant.
Mas a maioria das implementações de currying no JavaScript são avançadas, como descrito: elas também mantêm a função chamável na variante com múltiplos argumentos.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"a maioria das implementações ... são avançadas" — concordância: com "a maioria de + plural" ambas são aceitas, mas o original "as described" + "elas também mantêm" fica ambíguo. Considere "a maioria das implementações ... é avançada, como descrito: também mantém a função chamável..." para manter sujeito único e evitar "elas" referindo-se a implementações vs. funções.

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