These are chat archives for ramda/ramda

19th
Apr 2018
Sourav Chatterjee
@chattes
Apr 19 2018 05:59
Hi All, I need a small example on how to refactor API calls using pipeP, just want to understand how to handle resolve and reject
Here is the current code
``
request({ method: 'post', url: '/signin/frontm', data: { user: { email, password, }, }, }) .then(response => this.handleSuccess(response)) .catch(error => this.handleError(error))
Sourav Chatterjee
@chattes
Apr 19 2018 06:10
    request({
      method: 'post',
      url: '/signin/frontm',
      data: {
        user: {
          email,
          password,
        },
      },
    })
      .then(response => this.handleSuccess(response))
      .catch(error => this.handleError(error))
Sourav Chatterjee
@chattes
Apr 19 2018 06:34
I am interested in how to handle the rejection or the catch()
Joshua Rowe
@omnisci3nce
Apr 19 2018 08:08
Are either Typescript or Flow worth it with functional programming>
which one is better do you think?
Daniel Rodríguez Rivero
@danielo515
Apr 19 2018 10:26
@omnisci3nce I think neither of those works well with FP. If they worked well then they may be worth using them, but they get crazy with function application and currying
Mike Lambert
@lax4mike
Apr 19 2018 13:46
@chattes i haven't used pipeP before, but my impression is that pipeP returns a function that you need to invoke. At that time, you can then and catch it do deal with the side effects
check out the example for http://ramdajs.com/docs/#composeP
Daniel Rodríguez Rivero
@danielo515
Apr 19 2018 13:47
pipe indeed returns a function that you have to call
Pipe is used for creating functions on a point-free style
Mirza Brunjadze
@thisdotvoid
Apr 19 2018 14:33
@omnisci3nce I'm using typescript. Haven't seen problems yet, but haven't used many functions either. for example, this is correctly typed:
R.map(
    R.pipe(Pair.fromArray, R.partial(adoptPair, [hash])),
    R.splitEvery(2, nodes)
)
Mike Lambert
@lax4mike
Apr 19 2018 20:50
what's the best way to use Maybe (from folktale) with Ramda?
it seems that we need "safe" versions of all the ramda functions
eg.
Just({ name: "fred" })
  .map(R.prop("age"))
  .map(R.add(10));
that returns Just(NaN)...
Mike Lambert
@lax4mike
Apr 19 2018 20:55
to make this work correctly, we'd need safeProp
Just({ name: "fred" })
  .chain(safeProp("age"))
  .map(R.add(10));
Mike Lambert
@lax4mike
Apr 19 2018 22:19
i came up with this:
const safe = fn => R.curryN(
    fn.length, 
    R.compose(Maybe.fromNullable, fn)
);
which allows this:
Just(person)
  .chain(safe(R.prop("age")))
  .map(R.add(10))