These are chat archives for ramda/ramda

22nd
Mar 2018
Jin
@Justin-ZS
Mar 22 2018 01:53
Is there any function could traverse the list and break the Iteration if need.
I don't like use for and ‘some’/'every' just return boolean
Mike Lambert
@lax4mike
Mar 22 2018 02:18
hmm, R.any will break, but that's kind of hacky
there's also R.reduced
Arti Villa
@artivilla
Mar 22 2018 05:08

trying to convert this into ramada:

const toFloat = (num) => Number.parseFloat(num);
const getBal = (name, transactions) => {
    transactions.reduce((a, c) => {
        if (c.toAddress === name) {
            return assoc(c, balance, toFloat(c.amount) + toFloat(a));
        }
        if (c.fromAddress === name) {
            return assoc(c, balance, toFloat(a) + toFloat(c.amount));
        }
        return c.balance;
    }, 0);
    return transactions;
};

but i need to return trasnactions bk. not the acc.

Andris Praulitis
@andrispraulitis
Mar 22 2018 16:13
Hi, can someone help with combining 2 lists + grouping by prop + summing value?
Mike Lambert
@lax4mike
Mar 22 2018 16:19
what's your data look like?
Andris Praulitis
@andrispraulitis
Mar 22 2018 16:20
have commented expected result
not really that good with ramda, just basics
Mike Lambert
@lax4mike
Mar 22 2018 16:25
you can look into R.groupBy or R.groupWith
Andris Praulitis
@andrispraulitis
Mar 22 2018 16:27
I tried but no luck
Mike Lambert
@lax4mike
Mar 22 2018 16:28
i think you'll need to compose R.groupBy with some other steps
Mike Lambert
@lax4mike
Mar 22 2018 16:36
hmm, this is a tough one
i'd probably focus on writing a function that merges 2 records together
Andris Praulitis
@andrispraulitis
Mar 22 2018 16:37
and this ain't it, I have further plans for this
Mike Lambert
@lax4mike
Mar 22 2018 16:37
that's where functional programming shines though, solve the small problems, and compose them together to solve the bigger problems
maybe R.mergeWithKey could do something
Andris Praulitis
@andrispraulitis
Mar 22 2018 16:43
i'll need 2 actions with this
summing prop value is one, and the other is combining nested list
Mike Lambert
@lax4mike
Mar 22 2018 16:56
how about something like this: https://goo.gl/5PemdY
Andris Praulitis
@andrispraulitis
Mar 22 2018 16:59
ok this is what I need
now need to combine another prop
Mike Lambert
@lax4mike
Mar 22 2018 17:02
your sumStock could look like this:
const sumStock = (k, l, r) => R.cond([
  [R.equals("stock"), () => R.add(l, r)],
  [R.always, () => r]
])(k);
so you can add other keys there
Andris Praulitis
@andrispraulitis
Mar 22 2018 17:08
thanks
Mike Lambert
@lax4mike
Mar 22 2018 17:08
:thumbsup: