These are chat archives for ramda/ramda

9th
Sep 2016
Kurt Milam
@kurtmilam
Sep 09 2016 01:40
This message was deleted
Tim Reynolds
@timReynolds
Sep 09 2016 09:32
Could anyone point me to the correct way to write this. I'm struggling as both parts of the compose need state at some point;
export const getFinanceProvidersWithSelected = (state) => {
const mapSelectedOnSelectedTypeId = R.compose(mapSelected(R.prop('typeId')), getSelectedFinanceProviderTypeId)(state);
return R.compose(R.map(mapSelectedOnSelectedTypeId), getFinanceProviders)(state);
};
I can provide more context about some of those methods if required
what i'm really looking for is to have a single expression and remove the declaration of mapSelectedOnSelectedTypeId
Keith Alexander
@kwijibo
Sep 09 2016 10:48
export const getFinanceProvidersWithSelected = (state) => {
    const mapSelectedOnSelectedTypeId = R.pipe(
     getSelectedFinanceProviderTypeId
   , mapSelected(R.prop('typeId'))
 )
    return R.pipe( 
        getFinanceProviders
        , R.map(mapSelectedOnSelectedTypeId(state))
        )(state)
};
(just reformatting to read with highlighting and without scrolling)
Keith Alexander
@kwijibo
Sep 09 2016 11:00
const mapSelectedOnSelectedTypeId = R.pipe(
                             getSelectedFinanceProviderTypeId
                           , mapSelected(R.prop('typeId'))
                         )
export const getFinanceProvidersWithSelected = (state) =>  
    R.pipe(
          getFinanceProviders
        , R.map(mapSelectedOnSelectedTypeId(state))
    )(state)
I'd probably go for something like that
Tim Reynolds
@timReynolds
Sep 09 2016 11:02
Ok so just moving the mapSelectedOnSelectedTypeId definition out of the function
Keith Alexander
@kwijibo
Sep 09 2016 11:02
it is possible to get rid of the => functions with R.converge and R.useWith, but personally I find those trickier to read the flow of
Tim Reynolds
@timReynolds
Sep 09 2016 11:02
will read the docs on those two, not used them before
Keith Alexander
@kwijibo
Sep 09 2016 11:04
Sanctuary also provides a bunch of combinator functions https://sanctuary.js.org/
Denis Stoyanov
@xgrommx
Sep 09 2016 11:48
@kwijibo ? K,S,I,C? Also W will be very useful because W is join for function as monad
@kwijibo But we can implement it only with one basis X
Keith Alexander
@kwijibo
Sep 09 2016 12:36
@xgrommx nice
Denis Stoyanov
@xgrommx
Sep 09 2016 13:12
Bravi
@Bravilogy
Sep 09 2016 13:51

@FeliciousX I used R.flip:

const power = R.flip(Math.pow);

:D

so a working example would be:
const power = R.flip(Math.pow);
const squared = power(2);

let numbers = [1, 2, 3, 4, 5, 6];
console.log(R.map(squared, numbers));
Barry G
@bgits
Sep 09 2016 14:07
how might I drop from a listA where the id field of each object in the list matches an id field of any object in listB?
Ivan Demchenko
@raqystyle
Sep 09 2016 14:54
hi guys! quick question: I need a zipWith3 function (to use it with a -> a -> a -> a). Is there a way to simulate it?
Andrea Scartabelli
@ascartabelli
Sep 09 2016 14:58
@bgvianyc I only know Ramda superficially, but what you want to do is filter. Something like this maybe.
@bgvianyc (there's probably a shorter way, though)
LeonineKing1199
@LeonineKing1199
Sep 09 2016 14:59

@raqystyle

Not in Ramda, no, as far as I'm aware. I've created something similar using a zip range and my own transform function. So, shameless plug, shameless plug, shameless plug! Basically, create a range out of any number of arrays, transform them with your function.

Ivan Demchenko
@raqystyle
Sep 09 2016 15:00
@LeonineKing1199 yes, I also wrote it on my own. But I was just wandering that maybe there is simple way to emulate it and that is why it is not included
LeonineKing1199
@LeonineKing1199
Sep 09 2016 15:01
Oh, well then you don't need any help at all
Ivan Demchenko
@raqystyle
Sep 09 2016 15:02
yeah, actually, my implementation is fairly simple.
const zipWith3 = R.curry((fn, arr1, arr2, arr3) => {
  return arr1.map((x, i) => fn(x, arr2[i], arr3[i]));
})
Denis Stoyanov
@xgrommx
Sep 09 2016 15:13
@raqystyle
const zipWith3 = R.curry((fn, arr1, arr2, arr3) => {
  return arr1.slice(0, Math.min(...[arr1, arr2,arr3].map(l => l.length)).map((x, i) => fn(x, arr2[i], arr3[i]));
})
Andrea Scartabelli
@ascartabelli
Sep 09 2016 15:18
@bgvianyc ok, had a look at the docs: this is quite better
Barry G
@bgits
Sep 09 2016 15:20
@ascartabelli nice
Ivan Demchenko
@raqystyle
Sep 09 2016 15:27
@xgrommx I see your point (I hope :smile: ). but I don't understand why do you need to slice the 1st array
Denis Stoyanov
@xgrommx
Sep 09 2016 15:29
@raqystyle const zipArray = fn => sources => Array.from(Array(Math.min(...sources.map(s => s.length))), (_, i) => fn(...sources.map(s => s[i])));
Barry G
@bgits
Sep 09 2016 15:35
@ascartabelli except I'm trying to make a curried function, how can I modify so it reverses the order of the last two arguments?
Andrea Scartabelli
@ascartabelli
Sep 09 2016 15:41
@bgvianyc Ramda's functions are already auto-curried, so I suppose you can flip(differenceWith(eqProps("id")))
also I think you can use placeholders: differenceWith(eqProps("id"), __, b)
sorry for the bad paste
Andrea Scartabelli
@ascartabelli
Sep 09 2016 15:45
I don't know if I can forgive you
flip should work actually, let me check
@bgvianyc seems to work just fine: have I missed something?
Barry G
@bgits
Sep 09 2016 15:49
I see, I was building up wrong
Andrea Scartabelli
@ascartabelli
Sep 09 2016 15:49
also symmetricDifferenceWith performs a very different operation: "Finds the set (i.e. no duplicates) of all elements contained in the first or second list, but not both."
Barry G
@bgits
Sep 09 2016 15:57
I agree with different, not very :smile:
Andrea Scartabelli
@ascartabelli
Sep 09 2016 15:57
eheheh, fair enough
Ivan Demchenko
@raqystyle
Sep 09 2016 19:11
@xgrommx thanks! I didn't know that array.from takes also mapping function. crazy cool stuff! thanks!