Skip to content

fix#36

Open
Riim wants to merge 1 commit into
thisables:masterfrom
Riim:patch-1
Open

fix#36
Riim wants to merge 1 commit into
thisables:masterfrom
Riim:patch-1

Conversation

@Riim

@Riim Riim commented Sep 17, 2016

Copy link
Copy Markdown

No description provided.

@hemanth

hemanth commented Sep 18, 2016

Copy link
Copy Markdown
Collaborator

You got a chance to look at Travis?

@hemanth

hemanth commented Sep 18, 2016

Copy link
Copy Markdown
Collaborator

Please provide a description for the PR.

@davidchase

Copy link
Copy Markdown
Member

probably should also use specific node versions in travis and not use io.js anymore?

@hemanth

hemanth commented Sep 19, 2016

Copy link
Copy Markdown
Collaborator

Well, that's another fix.

Currently failing:

✖ handles length properly, …
✖ …even after partial application
✖ shaves off extra parameters

@Riim

Riim commented Sep 19, 2016

Copy link
Copy Markdown
Author

.slice(0, len) непонятно зачем, что если каррируемая функция принимает нечёткое число аргументов:

let sum = curry(function(firstNum, ...otherNums) {
    return otherNums.reduce((sum, num) => sum + num, firstNum);
}, placeholder, placeholder);
console.log(sum(1)(2, 3)); // => 3 ??? I think that should be 6

Проверка на containsPlaceholder тоже становиться не нужна.
Арность не обязательно устанавливать при вызове return _curry(initialArgs)();, хотя это уже не важно, но всё же.
Для себя сделал так:

export default function curry(fn, ...initialArgs) {
    let len = Math.max(fn.length, initialArgs.length);

    function _curry(args, fixArity) {
        function f(...newArgs) {
            let mergedArgs = mergeArguments(args, newArgs);

            return getActualLength(mergedArgs) >= len ?
                fn.apply(void 0, mergedArgs) :
                _curry(mergedArgs, true);
        }

        return fixArity ? setArity(len - getActualLength(args), f) : f;
    }

    return _curry(initialArgs)();
}

let sum = curry(function(firstNum, ...otherNums) {
    return otherNums.reduce((sum, num) => sum + num, firstNum);
}, placeholder, placeholder);
console.log(sum(1)(2, 3)); // => 6

Спасибо за внимание и удачи вам))

@Riim

Riim commented Sep 27, 2016

Copy link
Copy Markdown
Author

Как-то зависло всё, выложил свою реализацию: https://www.npmjs.com/package/@riim/curry

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.

3 participants