These are chat archives for ramda/ramda

5th
Mar 2017
Travis LaDuke
@laduke
Mar 05 2017 06:01
whoa
isidorosp
@isidorosp
Mar 05 2017 08:48
Hi guys. Anyone around? I'm looking for some help on how to filter down an object based on multiple "contains"
Daniel Skelton
@dskelton-r7
Mar 05 2017 08:52
Sounds like where ? and then use contains inside that?
isidorosp
@isidorosp
Mar 05 2017 08:54
how can I chain contains for multiple n values (I don't knwo how many of these values I will have to look for)
i basically got it to work for two with a AND(contains,contains) inside a filter but obvious it's not very robust
I tried wrapping the contains in an allPass but that doesn't seem to work.
Daniel Skelton
@dskelton-r7
Mar 05 2017 08:57
Can you show an example of what you have?
isidorosp
@isidorosp
Mar 05 2017 08:57
yes
I just paste the REPL url right?
Daniel Skelton
@dskelton-r7
Mar 05 2017 08:58
yea thats fine
isidorosp
@isidorosp
Mar 05 2017 08:58
deleted...
character limit
the idea is to go into the "runes" property of every item and then see if "runes" includes all of a number of chosen runes (e.g. I did this with just two, but it could go up)
Daniel Skelton
@dskelton-r7
Mar 05 2017 09:15
const matchingRunes = (runes) => filter(compose(any(flip(contains)(runes)), prop('runes')), rws);
MatchingRunes(['Tir', 'Eth'])
Should really pass the rws into that function too
isidorosp
@isidorosp
Mar 05 2017 09:18
seems to be giving me an "or" match
also how the heck did you come up with that? :D
impressive
Daniel Skelton
@dskelton-r7
Mar 05 2017 09:21
Superb docs :)
isidorosp
@isidorosp
Mar 05 2017 09:22
heh
any idea on how I can turn it into an "and" match? (or rather "at least" i.e. contains at least these x runes in matchingRunes)
Daniel Skelton
@dskelton-r7
Mar 05 2017 09:55
  compose(
    equals(0),
    prop('length'),
    difference(['Tir', 'Bang']),
    prop('runes')
  ), 
 rws);
const matchingRunes = (runes) => 
filter(
  compose(
    equals(0),
    prop('length'),
    difference(runes),
    prop('runes')
  ), 
 rws);
Might work
isidorosp
@isidorosp
Mar 05 2017 09:59
think this one is it :D
Daniel Skelton
@dskelton-r7
Mar 05 2017 10:00
sweet :)
isidorosp
@isidorosp
Mar 05 2017 10:00
where does prop('length') come from?
like array.length?
Daniel Skelton
@dskelton-r7
Mar 05 2017 10:01
Yea, its the length property on the array
isidorosp
@isidorosp
Mar 05 2017 10:01
how do you know it's on the array and not like "rws" which prop('runes') is?
I def have to read mroe about FP basics it looks like :(
Daniel Skelton
@dskelton-r7
Mar 05 2017 10:02
difference will return an array of the difference between the input and the runes array. Then if that is equal to 0 they are both included so it matches
isidorosp
@isidorosp
Mar 05 2017 10:03
so is it this: filter rws where difference of ('runes' vs 'runes_ourarray') has a length of 0
Daniel Skelton
@dskelton-r7
Mar 05 2017 10:04
yep
isidorosp
@isidorosp
Mar 05 2017 10:04
and if you were to use pipe instead of compose you'd just flip the order on everything and it'd work the same way?
Daniel Skelton
@dskelton-r7
Mar 05 2017 10:04
Ah yea, I always use compose but its just personal preference
isidorosp
@isidorosp
Mar 05 2017 10:05
just trying to get the hang of it. just started using R yesterday and it's quite different to the way I'd do it in normal JS or _/lodash
thanks a lot for your help :)
Daniel Skelton
@dskelton-r7
Mar 05 2017 10:07
No worries at all :)
akilesh
@akileshv
Mar 05 2017 14:18
[{a: 1b:1}, {a:2,b:2}] and [1,2] i want combine these two array and produce result like [{a:1,b:1,c:1},{a:2,b:2,c:2}]
Jonas Windey
@jonaswindey
Mar 05 2017 14:47
hi, I'm trying to reduce a value from a custom function and I don't want to send the acc + value to that function bud I'd like to use R.add() instead
any suggestions on how to do this?
Jonas Windey
@jonaswindey
Mar 05 2017 16:43
nvm, fixed it with R.sum()
Jonas Windey
@jonaswindey
Mar 05 2017 16:58

other noob question, why is the following working:

const kpiValue = (definition, year, month, role) =>
  compose(
    Math.floor,
    parseFloat
  )(pathOr(0, ['kpiData', definition, year, month, 'value'], role))

but

const kpiValue = (definition, year, month, role) =>
  compose(
    Math.floor,
    parseFloat,
    pathOr(0, ['kpiData', definition, year, month, 'value'], role))

Isn't? (Error: First argument to _arity must be a non-negative integer no greater than ten)
The docs say: The rightmost function may have any arity; the remaining functions must be unary.

isn't the last function considered the 'rightmost' ?
Travis LaDuke
@laduke
Mar 05 2017 17:05
I don't think anything is calling compose in the second one, so kpiValue is returning a function?
Travis LaDuke
@laduke
Mar 05 2017 17:11
Or, pathOr is returning a value because it's fully applied there
so it's like you have compose(Math.floor, parseFloat, 0)
Brad Compton (he/him)
@Bradcomp
Mar 05 2017 17:13
@akhileshv You can use:
R.zipWith
[Function: f2]
Brad Compton (he/him)
@Bradcomp
Mar 05 2017 17:15
This message was deleted
ram-bot
@ram-bot
Mar 05 2017 17:15
a is not defined
Jonas Windey
@jonaswindey
Mar 05 2017 17:15
@laduke thanks, so compose(Math.floor, parseFloat, 0) isn't supposed to work either and give an error?
Brad Compton (he/him)
@Bradcomp
Mar 05 2017 17:15
@ram-bot
const a1 = [{a: 1, b: 1}, {a: 2, b: 2}];
const a2 = [1, 2];

zipWith((fst, snd) => merge(fst, {c: snd}), a1, a2);
ram-bot
@ram-bot
Mar 05 2017 17:15
[ { a: 1, b: 1, c: 1 }, { a: 2, b: 2, c: 2 } ]
Brad Compton (he/him)
@Bradcomp
Mar 05 2017 17:15
There we go
Travis LaDuke
@laduke
Mar 05 2017 17:18
right, you could do like compose(..., pathOr(0, ['kpiData', definition, year, month, 'value'])(role) i think
Jonas Windey
@jonaswindey
Mar 05 2017 17:20
that makes sense, thanks
Travis LaDuke
@laduke
Mar 05 2017 17:21
I'm helping!
akilesh
@akileshv
Mar 05 2017 17:40
tx @Bradcomp