These are chat archives for ramda/ramda

19th
Mar 2019
Simon Bailey
@thebailers
Mar 19 08:40
@bijoythomas That is spot on, thanks so much
Simon Bailey
@thebailers
Mar 19 10:44
Does anyone have any pointers on how to handle this with Ramda? How can I throw an error if the item is not found in the array?
const targetColumnIndexes = targetColumns.map(h => {
    if (header.indexOf(h) == -1) {
      throw new Error(`Target Column Name not found in CSV header column: ${h}`)
    }
    return header.indexOf(h)
  })
Ben Briggs
@ben-eb
Mar 19 11:39
@thebailers What's wrong with this code, if you want to throw?
Mike Chen
@mike442144
Mar 19 11:40
why don't you return null?
Simon Bailey
@thebailers
Mar 19 11:41
the script can’t run if the column isn’t found
I need to alert the user running the script that they provided invaid data
Mike Chen
@mike442144
Mar 19 11:42
you use in an API?
for a developer?
Simon Bailey
@thebailers
Mar 19 11:42
And not sure how to write this using ramda… I wrote a stack overflow post which explains it: https://stackoverflow.com/questions/55239612/how-to-handle-errors-in-ramda
The csv data is from an api
Mike Chen
@mike442144
Mar 19 11:43
it has nothing to do with ramda..
Simon Bailey
@thebailers
Mar 19 11:43
No, I am rewriting the script using ramda
Mike Chen
@mike442144
Mar 19 11:43
if you wanna handle exception in a safe way, should use Either or Maybe monad.
Simon Bailey
@thebailers
Mar 19 11:43
so the above code works fine - but i want to rewrite it in a functional way using ramda… i have already done other parts of the script, but am stuck here
@mike442144 can’t see maybe in the ramada docs?
Mike Chen
@mike442144
Mar 19 11:44
Okay, you could do some research of Either or Maybe monad
Ben Briggs
@ben-eb
Mar 19 11:45
Mike Chen
@mike442144
Mar 19 11:45
use require('ramda-fantasy');
Ben Briggs
@ben-eb
Mar 19 11:46
Ramda fantasy isn't being developed
Mike Chen
@mike442144
Mar 19 11:48
Wow, I don't know the first one.
Simon Bailey
@thebailers
Mar 19 11:49
Thanks guys, I will have a look at these
Mike Chen
@mike442144
Mar 19 11:49
how is that
Jacob Bogers
@Jacob_Bogers_twitter
Mar 19 11:50
hi
I have isolated an issue i am trying to solve
creaing a volume bind in docker
i made minimalist example here
can someone take a look?
Mike Chen
@mike442144
Mar 19 11:52
are you sure it is related to ramda/
Ben Briggs
@ben-eb
Mar 19 11:56
@thebailers No worries :)
Nika
@overflowz
Mar 19 20:30
Hey, I'm trying to wrap my head around .reduce and .then but I don't really understand what's going on. I'm trying to reduce promises into single one (by chaining them) and return one final promise, but for some reason I get really weird errors. Can you please help me out with that? P.S. I'm new to gitter and I'll try my best to format the code.
const Promise = require('bluebird');
const R = require('ramda');

const m1 = Promise.method(_ => {
  console.log('executing m1');
  return Promise.delay(2000);
});

const m2 = Promise.method(_ => {
  console.log('executing m2');
  return Promise.delay(2000);
});

// I'm trying to implement this into ramda.
// const lazyReduceP = promises => promises.reduce((acc, x) => acc.then(_ => x()), Promise.resolve());

// what's wrong here?
const lazyReduceP = R.reduce(
  R.then(R.call),
  Promise.resolve(),
);

console.time('promise');
lazyReduceP([m1, m2]).then(_ => console.timeEnd('promise'));
expected output should be:
executing m1 (wait for 2 seconds after)
executing m2 (wait for 2 seconds again)
promise: time
Nika
@overflowz
Mar 19 20:41
never mind, problem lays in R.call since it tries to call returned value rather than currentValue.
Brad Compton (he/him)
@Bradcomp
Mar 19 20:43
Yeah, I think you might need R.flip(R.then)
Nika
@overflowz
Mar 19 20:48
I tried that too but didn't worked ;p
Brad Compton (he/him)
@Bradcomp
Mar 19 20:53
Worked for me!
const sleep = n => new Promise((res) => setTimeout(() => res(), n));

const m1 = () => sleep(2000).then(() => console.log('M1'));

const m2 = () => sleep(2000).then(() => console.log('M2'));

const lazyReduceP = R.reduce(
  R.flip(R.then),
  Promise.resolve(),
);

console.time('promise');
lazyReduceP([m1, m2]).then(_ => console.timeEnd('promise'));
Nika
@overflowz
Mar 19 21:47
wait, it did!
I'm gonna wrap my head around now :D thanks!