These are chat archives for ramda/ramda

30th
May 2016
Will White
@willnwhite
May 30 2016 14:17
Hey. I'm building an index of functions by their inputs and output types. Are ramda functions available in format:
{name: "length", inputs: ["array"], output: "number"}?
Hardy Jones
@joneshf
May 30 2016 14:22
@rjmk I think you still need the name amount of information with the GADT version.
@rjmk though that makes me wonder if it can't be simplified even further with something like typeclass prolog...
Will White
@willnwhite
May 30 2016 15:20

uniq.js has the lines

@param {Array} list The array to consider.
@return {Array} The list of unique items.

What are the @s? I'm wondering if they're part of a system I can hook into to generate the JSON.

Hardy Jones
@joneshf
May 30 2016 15:24
jsdoc
Rafe
@rjmk
May 30 2016 15:24
@willnwhite It looks like this might be of use to you: https://github.com/ramda/ramda/blob/master/scripts/doc-blob
@joneshf That makes sense. I guess I was thinking that the dependent typed version involved more information than it strictly used (the n). Is that so or am I confused?
Will White
@willnwhite
May 30 2016 15:27
Thanks.
Hardy Jones
@joneshf
May 30 2016 15:33
@rjmk ah, I think you can drop that on the dependent type version as well if you want. I figured you were using it to enforce a certain number of composed functions.
Will White
@willnwhite
May 30 2016 15:40
@rjmk I'm running that now but it's saying Error: ENOENT: no such file or directory, open 'doc.yaml'
There's no doc.yaml in its directory, nor in the repo.
@rjmk I thought running it might give me JSON I can map to my schema. Is that correct?
Rafe
@rjmk
May 30 2016 16:28
@joneshf Yeah that was the idea but I don't think I did anything with it
@willnwhite It looks like it might! I was just searching around in the repo and spotted that so I'm afraid I can't help much more
Will White
@willnwhite
May 30 2016 17:15
@rjmk Cool, that makes sense. Thanks anyway. I've decided it might be better to cover the standard things first now, like the DOM API, before libraries. I'll keep thinking about how I could use JSDoc to help. Hopefully by the time it has the standard libraries I will have worked out a nice way to collect new libraries. Thanks again.
LeonineKing1199
@LeonineKing1199
May 30 2016 17:33

@CrossEye

Hey, I came up with a dummy implementation of variadic currying! It even supports some very basic placeholding. Basically, it's very, very, very fragile code right now but I do have some tests and things are looking promising.

'use strict';

const assert = require('assert');
const R = require('ramda');

const vCurry = function(f) {
    // assume valid f
    const args = Array.from(arguments).slice(1, arguments.length);
    return function() {
        // different 'arguments'
        const tmpArgs = args.slice();
        const curryArgs = Array.from(arguments).reverse();

        for (let i = 0; i < tmpArgs.length; ++i) {
            if (tmpArgs[i].isPlaceholder_) {
                tmpArgs[i] = curryArgs.pop();
            }
        }

        // remember to set everything back to the proper order
        return f.apply(f, tmpArgs.concat(curryArgs.reverse()));
    };
};

const __ = { isPlaceholder_: true };

const accumulate = function() {
    return R.reduce((acc, val) => (acc + val), 0, Array.from(arguments));
};

// first off, check if our accumulator actually works
assert(accumulate(1, 2, 3, 4) === 10);
assert(accumulate(1, 2, 3) === 6);
assert(accumulate(1, 2) == 3);
assert(accumulate(1) == 1);

// Cool, now let's test vCurry out...

// Okay, so because variadics are weird, we have to change
// up the currying interface

// This means that vCurry takes the function to curry as well
// as a variadic list of arguments to curry it with. This is what
// determines the arity of the function at the time of currying
// and allows the placeholder mechanism as well as some automatic
// currying until the initial arity is reached.

// it should support a basic, non-placeheld syntax
{
    const g = vCurry(accumulate, 1, 2, 3, 4);
    assert(g() === 10);

    const h = vCurry(g, 5);
    assert(h() === 15);
    assert(h(6) === 21);
    assert(h(6, 7) == 28);
}

// we should be able to do some awesome placeholding
{
    const g = vCurry(accumulate, 1, __, 3, __);
    assert(g(2, 4) === 10);
    assert(g(2, 4, 5) === 15);
}
Things it doesn't yet support are more automatic forms of currying. For example, if we're using n placeholders and the user passes in less than n arguments, we don't re-curry. This is a next big to-do. But aside from that, I think it works. If you or anyone can come up with some extra test cases, I'd really appreciate it too.