These are chat archives for ramda/ramda

3rd
Apr 2017
Alastair Hole
@afhole
Apr 03 2017 14:39
map( invoker(0, 'produceNewO') ) would that work?
Raine Virta
@raine
Apr 03 2017 15:02
I don't really find either of those an improvement over the original
Raine Virta
@raine
Apr 03 2017 15:07
livescript has interesting sugar for that. map((.produce-new-o!))
Casey Link
@Ramblurr
Apr 03 2017 16:19
@miwillhite 's suggestion is only useful if I am calling ProduceNewO multiple times, in reality it is one off methods on different objects
I was just thinking of Java 8's method reference o::produceNewO, but JS doesn't have any syntactic helpers like that
so I'll just stick with (o) => o.produceNewO()
that live script example is interesting though
Matthew Willhite
@miwillhite
Apr 03 2017 16:21
@Ramblurr ah yeah, with one-off’s I think your solution is as good as it’s going to to get ;P
Casey Link
@Ramblurr
Apr 03 2017 16:22
an unrelated question, since Ramda is all about functional flows and immutable data, what do you use to enforce immutability?
Matthew Willhite
@miwillhite
Apr 03 2017 16:22
unless…you have a strict set of objects that you know you are going to be calling these functions on
then you could use cond to determine which object and call it’s initializer. Having all of your cases in one place
Casey Link
@Ramblurr
Apr 03 2017 16:23
Also are there any example of large codebases that use Ramda in a "good way" I could browse, because the simple examples in the Ramda articles are great, but a real life messy code base that I'm trying to slowly clean up and bring some sanity too is a far cry from those examples
Brad Compton (he/him)
@Bradcomp
Apr 03 2017 16:28
@Ramblurr Ramda doesn't enforce immutability in code that you write, but none of the Ramda functions will modify their input data.
Matthew Willhite
@miwillhite
Apr 03 2017 16:29
@Ramblurr I too started (and am still working on) a really messy code base. I’d say just start with a function, prodecure, module at a time.
@Ramblurr Are you working with a particular framework?
Those kinds of limits make it a little easier to refactor I think.
Shane Keulen
@SeeThruHead
Apr 03 2017 22:52

hey all, curious is there something like this in ramda or ramda-sanctuary:

const dict = {
  1: 'one',
  2: 'two',
  3: 'three'
};

const list = [2, 3, 1];

const orderBy = dict => R.map(x => dict[x]);
const orderBy2 = R.map(R.prop);

orderBy(dict)(list);
orderBy2(dict)(list);

where i'd like to remove the argument dict and have it passed in to R.prop, which would return me the proper map

Raine Virta
@raine
Apr 03 2017 22:59
@ram-bot
const dict = {
  1: 'one',
  2: 'two',
  3: 'three'
};

const list = [2, 3, 1];
map(prop(__, dict), list)
ram-bot
@ram-bot
Apr 03 2017 22:59
[ 'two', 'three', 'one' ]
Shane Keulen
@SeeThruHead
Apr 03 2017 23:00
you're accessing dict from the outer scope there
Raine Virta
@raine
Apr 03 2017 23:00
what does the desired function look like?
const orderBy = (dict, list) =>
  map(prop(__, dict), list)
point-free version of this?
Shane Keulen
@SeeThruHead
Apr 03 2017 23:02
yeah exactly
Shane Keulen
@SeeThruHead
Apr 03 2017 23:08
const fakeCombinator = f1 => f2 => a1 => a2 => f2(x => f1(x)(a2), a1);

const orderBy = fakeCombinator(prop)(map);

orderBy(list)(dict);
Raine Virta
@raine
Apr 03 2017 23:12
@ram-bot
const dict = {
  1: 'one',
  2: 'two',
  3: 'three'
};

const list = [2, 3, 1];

const orderBy = useWith(map, [ flip(prop), identity ])
orderBy(dict, list)
ram-bot
@ram-bot
Apr 03 2017 23:12
[ 'two', 'three', 'one' ]
Raine Virta
@raine
Apr 03 2017 23:23
> compose(map, flip(prop))(dict)(list)
[ 'two', 'three', 'one' ]