These are chat archives for ramda/ramda

8th
May 2017
Rick Medina
@rickmed
May 08 2017 14:25
can anyone pls recommend me a tiny tiny browser only simple http lib?
Denis Stoyanov
@xgrommx
May 08 2017 14:35
axios
James Forbes
@JAForbes
May 08 2017 14:44
Somewhat strange suggestion but: Mithril is about 10kb smaller than axios, and it includes a handy http request function in it (plus its also a frontend framework)

the request module on its own is only 5kb unminified, but I think there's no bundles for that.

https://github.com/MithrilJS/mithril.js/blob/next/request/request.js

If you're using a bundler though: require('mithril/request') would work
maybe too barebones
Denis Stoyanov
@xgrommx
May 08 2017 14:57
fetch is bullshit
axios better
Rónán
@ronanyeah
May 08 2017 14:57
@xgrommx come on... mzabriskie/axios#41
Denis Stoyanov
@xgrommx
May 08 2017 14:58
anyway Rx5 Observable.ajax
Zephilim
@Zephilim
May 08 2017 15:12
Anyone know how to use memoize function properly? I'm having a bit of strife with it
I'm trying to wrap a call to reduce on an array inside a call to memoize and the result keeps being undefined.
Denis Stoyanov
@xgrommx
May 08 2017 15:15
Zephilim
@Zephilim
May 08 2017 15:15
the following isolated bit of code works ok:
["a", "b", "c"].reduce((acc, o, index, all) => acc.concat( all.slice(index + 1).map(x => [o, x])), []);

However, when I wrap this as follows:

let fn = R.memoize((arr) => {
arr.reduce((acc, o, index, all) => acc.concat( all.slice(index + 1).map(x => [o, x])), []);
});

and then invoke the function fn:

let result = fn(["a", "b", "c"]);

result is undefined!

Robert Mennell
@skatcat31
May 08 2017 16:15
@Zephilim your function is missing a return statement. input => { //inside brackets? Return needed }
Zephilim
@Zephilim
May 08 2017 16:17
argghhh, thanks, I can't believe I missed that
shame my linter didnt pick that up (eslint)
Robert Mennell
@skatcat31
May 08 2017 16:27
@Zephilim having functions with functionality and no return is a proper design principle in JS.
Zephilim
@Zephilim
May 08 2017 16:30
Yeah of course. I'm currently going from traditional oo languages (C++/C#) to javascript and I keep tripping over fundamentals in JS, and getting things mixed up! Arg. I'll get there in the end
Of course, there is no reason why eslint would pick that up, when I think about it. Its just that in C++/C#, this would not have tripped me up as it would simply have been a compile error.
Robert Mennell
@skatcat31
May 08 2017 16:32
@Zephilim https://www.typescriptlang.org/ Javascript transpiler with typing. Might make it a little easier
Zephilim
@Zephilim
May 08 2017 16:34
Yeah, that's on my list of things to learn. I'm just concentrating on learning JS first, because you still need to know it in order to understand TS.
Jonah
@jonahx
May 08 2017 17:08
interesting little micro-problem. you have a list of two-character strings, like [‘ab’, ‘ac’, ‘ba’, ‘dc, …]. you want to filter it such that there is only one instance of each of the possible transpositions. that is, if the original list contains ab and ba, the filtered list must contain exactly one of them, but not both. this is obviously trivial to solve procedurally in O(n^2) — is there a compact ramda solution for it? generalizing, i find that problems like this where you want to use a filter but where the predicate of the filter needs to refer to other elements in the list, can be pesky...
Zephilim
@Zephilim
May 08 2017 17:15
Given an array, I want a function to produce all unique pair combinations (where "ba" can be considered the same as "ab" and should be skipped). So for ["a", "b", "c"] the function should return: [["a", "b"], ["a", "c"], ["b", "c"]]. I tried to find a fucntion in ramda to do this, but couldn't find one, so this is the solution. Since I will be calling the function many times, with the same arguments, I liked the idea of using Memoize, to make it more efficient.
Philipp Wille
@Yord
May 08 2017 17:23

@jonahx How about

const data = ['ab', 'ac', 'ba', 'dc']

pipe(
  groupBy(sortBy(identity)),
  values,
  chain(head)
)(data)

(not exactly O(n^2), but well... at least compact?)

Denis Stoyanov
@xgrommx
May 08 2017 17:25
why it not included ba?
Philipp Wille
@Yord
May 08 2017 17:28
I guess I am misusing sortBy here not on an array but on a string
Zephilim
@Zephilim
May 08 2017 17:28
Oh, that looks very new to me. I don't know what pipe/groupBy/chain do, but it looks interesting and definitely worth investigating.
James Forbes
@JAForbes
May 08 2017 17:29
in this very specific case you could replace values,chain,head with simply keys
Syaiful Bahri
@syaiful6
May 08 2017 17:29
@jonahx i think it just uniqWith
James Forbes
@JAForbes
May 08 2017 17:29
but only because these are strings we're dealing with
Jonah
@jonahx
May 08 2017 17:29
@Yord I’d say that’s a clever mis-use of sortBy :).
James Forbes
@JAForbes
May 08 2017 17:30
Why is it a misuse? Seems legit to me
Jonah
@jonahx
May 08 2017 17:30
@JAForbes I was just quoting him :)
James Forbes
@JAForbes
May 08 2017 17:30
ah :D
Philipp Wille
@Yord
May 08 2017 17:31
Well it is not documented as a function signature, so I am feeling kind of guilty ;)
Jonah
@jonahx
May 08 2017 17:31
@syaiful6 I think you’re right. uniqWith and function for equality based on transposition (or regular identity) seems the most ramda-esque solution here
James Forbes
@JAForbes
May 08 2017 17:31
@syaiful6 is right, but yeah pipe( groupBy( sortBy(identity)), keys) would work in this specific case too
Philipp Wille
@Yord
May 08 2017 17:32
@JAForbes (and keys is indeed a nice way to do the exact same thing here)
Syaiful Bahri
@syaiful6
May 08 2017 17:32
it just uniqWith(grouper, data), where gruper sum the charCode of both string and compare if it's equal
James Forbes
@JAForbes
May 08 2017 17:32
@Yord much more hacky than sorting a string :D
Jonah
@jonahx
May 08 2017 17:33
thanks everyone.
Zephilim
@Zephilim
May 08 2017 17:33
Thanks from me too
Philipp Wille
@Yord
May 08 2017 17:33
@JAForbes definitely ^^
Jonah
@jonahx
May 08 2017 17:36
@syaiful6 i think that would be a dangerous implentation. you could get accidental collissions of elements which were neither identical nor transposed, and thus overfilter your list
Syaiful Bahri
@syaiful6
May 08 2017 17:38
right, it's naive..
Rick Medina
@rickmed
May 08 2017 17:53
@JAForbes yeah, superagent is ~5kb gz, I think I might steal that module since I actually need it for stream functionality ( @xgrommx )
thanks @ronanyeah
Jesse Atkinson
@jsatk
May 08 2017 19:03
Hi all! I was just wondering how Ramda generates those gorgeous JS docs. I don’t see anything obvious in the github repo.