These are chat archives for ramda/ramda

29th
Feb 2016
Stefano Vozza
@svozza
Feb 29 2016 01:08
i'm invoking an aws lambda function multiple times over a very large array. there's a 6mb limit to the payload you can send to a lambda so i have to break the array into an array of arrays where each one is less than 6mb in size. this is what i've come up with, does anyone have a different solution?
const splitByLambdaSizeLimit = xs => {
    const limit = (Buffer.byteLength(JSON.stringify(xs)) / (1024 * 1024)) / 6;
    return limit < 1 ? [xs]
                  : R.chain(splitByLambdaSizeLimit, R.splitEvery(Math.ceil(xs.length / Math.ceil(limit)), xs));
};
James Forbes
@JAForbes
Feb 29 2016 01:25

@svozza does each item in the array have roughly the same structure/size? If so, it might be better to stringify the individual item, obtain its size, and then chunk the array into the needed lengths

This is because JSON.stringify can crash node quite easily on relatively large payloads. I've seen this before with Lambda

@svozza but I think your Buffer.byteLength idea is great
Stefano Vozza
@svozza
Feb 29 2016 06:27
Yeah, the structure of each item in the array is identical (they're basically a single Kinesis record) but they can be of wildly different sizes
Stefano Vozza
@svozza
Feb 29 2016 06:42
Actually, that's a good idea about sizing the items individually. i'm using highland so i can build up the each array piece by piece and push wihen they get to close to 6megs. it'll be more effiecient than the way i'm doing it now.
MySidesTheyAreGone
@MySidesTheyAreGone
Feb 29 2016 08:17
Hello, quick question; I was going through the Ramda build script to learn more about FP and I noticed this:
R.converge(R.equals, R.identity, R.sortBy(R.identity))
Line 104 on master. How does this even work? Shouldn't it be R.converge(R.equals, [R.identity, R.sortBy(R.identity)])? What am I missing?
Scott Christopher
@scott-christopher
Feb 29 2016 08:19
@MySidesTheyAreGone It's likely using an older version of Ramda (which used to have a variadic converge)
MySidesTheyAreGone
@MySidesTheyAreGone
Feb 29 2016 08:21
Oh ok, not a problem then. I'm always worried I misunderstand stuff and then I get bitten in my behind later.
Scott Christopher
@scott-christopher
Feb 29 2016 08:25
👍
Should be a fairly straightforward task to bring it up to date if anyone feels like it.
Hendrik Helwich
@hhelwich
Feb 29 2016 09:09
@Avaq: great!
Denys Mikhalenko
@prontiol
Feb 29 2016 09:28
Is there any reason to have flip to flip only 2 first arguments and not all of them?
Keith Alexander
@kwijibo
Feb 29 2016 11:58
@prontiol move the first to the last? Or something else?
Denys Mikhalenko
@prontiol
Feb 29 2016 14:19
reverse the arguments list
f(a,b,c) -> f(c,b,a)
this will work just the same as current flip implementation does for 2 arguments, but do reverse all arguments instead of swapping two first arguments, if there are more then 2
just wondering, why flip works this (limited to the first two arguments) way
Scott Sauyet
@CrossEye
Feb 29 2016 14:27
Functions parameters are generally ordered so that the parameter most likely to change comes last. Occasionally there's a good reason to do f(a, b, c) ~> g(b, a, c) when the ordering of the first two is not clear. But a full reversal seems likely to be unusual.
Hardy Jones
@joneshf
Feb 29 2016 15:31
@prontiol it's much harder to type the version of flip that you want. You have to introduce variadic functions, which brings in a slew of problems. For instance, look at call, We were just discussing the other day how it's much more complex than apply precisely because it is variadic.
type as in "Give a type signature," not type as in "Enter the keys with a keyboard."
Hardy Jones
@joneshf
Feb 29 2016 15:51
Except that argument falls out of the window, because the implementation of flip isn't so simple.
Scott Sauyet
@CrossEye
Feb 29 2016 16:42
Yes, our flip actually does accept variadic functions. :smile:. It is sometimes useful as it stands. I can'tn come up with a case where it would help as proposed those for larger-arity function. @prontiol: do you have some suggested uses?
David Chambers
@davidchambers
Feb 29 2016 17:06

@CrossEye, I came up with a nice permutations function:

//    permutations :: Number -> [a] -> [[a]]
const permutations = R.compose(R.sequence(R.of), R.flip(R.repeat));

I posted this on Stack Overflow.

Aldwin Vlasblom
@Avaq
Feb 29 2016 18:31
@davidchambers Very nice! :D
Scott Sauyet
@CrossEye
Feb 29 2016 21:11
I saw it on SO first and commented there. It doesn't actually give permutations (or n-combinations as was asked for there. ) instead it returns all k^n length-n sequences of elements drawn from the length-k list. The result should have length (k choose n).
David Chambers
@davidchambers
Feb 29 2016 21:12
Oh, you're right!
Scott Sauyet
@CrossEye
Feb 29 2016 21:14
It is a very elevator solution to that problem, however.
Elegant