These are chat archives for ramda/ramda

27th
May 2018
Dong Nguyen
@ndaidong
May 27 2018 02:03
hi everyone, how I can replace the logic operators in the check() function below with Ramda logic functions? Thanks.
const hasClient = true;

const sayHello = () => {
  console.log('Hello, bonjour, nihao');
  return true;
};

const doNothing = () => {
  console.log('Do nothing');
  return false;
};

const check = () => {
  return (hasClient || doNothing()) && sayHello();
}

check();
geo
@geomen888
May 27 2018 09:29
Thanks for advices I have found supply or error it is const pathToLegs = R.path(["json", "json", "routes"]); it's returns unefined. But WHY?????
I changed it to let pathToLegs = (obj: any) => R.path(["json", "json", "routes"], obj); but it does not helped
In TRY RAMDA works perfect :-))))
Stephan Meijer
@smeijer
May 27 2018 09:38
@ndaidong
const greet = R.ifElse(R.identity, sayHello, doNothing);
greet(hasClient);
Stephan Meijer
@smeijer
May 27 2018 09:48
Even without Ramda, I would prefer something like this, over your check. Your version is short, but not very readable:
// minimum change, flip it:
const check = (hasClient) => {
  return (hasClient && sayHello) || doNothing();
}

// similar, but making use of the right operators
const check = (hasClient) => {
  return hasClient ? sayHello() : doNothing();
}

// or, write it full out
const check = (hasClient) => {
  if (hasClient) {
    return sayHello();
  }

  return doNothing();
}
Stephan Meijer
@smeijer
May 27 2018 09:53

A couple of months ago I also tried make a lot of things functional, and "ramda only". But I get over that phase. I though I was being awesome, but the truth is; a lot of code became harder to read, and thereby harder to maintain.

I still use Ramda as utility belt. Kind of lodash replacement, because I like it's immutability, and the data last argument order (for currying). I stopped making all methods point-free. And I'm also using less ternary operators (return x ? y : a). I now finally realise, that it's often better to have a few extra lines of code, than that short snippet that's hard to read / understand.

geo
@geomen888
May 27 2018 09:57
I'm understand already nature of errors - it's qiuet simple - I'll try to recive ramda -functional responce into promise. In this case it takes more time for calculation and brokes promise which returns undefined
Daniel Rodríguez Rivero
@danielo515
May 27 2018 12:29

. I now finally realise, that it's often better to have a few extra lines of code, than that short snippet that's hard to read / understand.

I went through that phase too

Dong Nguyen
@ndaidong
May 27 2018 13:32
@smeijer thank you so much Stephan, your're rock! I'm writing an article about FP and here is an example. In which, I use all 3 ways you given: traditional if/else, ternary and logic operators. Then I tried to do with Ramda and, both, unless... but they didn't work. Once again, thank you.