Skip to content

Conversation

@Riim
Copy link

@Riim Riim commented Sep 17, 2016

No description provided.

@hemanth
Copy link
Collaborator

hemanth commented Sep 18, 2016

You got a chance to look at Travis?

@hemanth
Copy link
Collaborator

hemanth commented Sep 18, 2016

Please provide a description for the PR.

@davidchase
Copy link
Member

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

@hemanth
Copy link
Collaborator

hemanth commented Sep 19, 2016

Well, that's another fix.

Currently failing:

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

@Riim
Copy link
Author

Riim commented Sep 19, 2016

.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
Copy link
Author

Riim commented Sep 27, 2016

Как-то зависло всё, выложил свою реализацию: 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