These are chat archives for ramda/ramda

31st
May 2017
gmunguia
@gmunguia
May 31 2017 10:33
Hi there! I'm looking at the docs for transduce (http://ramdajs.com/docs/#transduce) , but failing to understand the example. The transducer function in the example doesn't seem like a transducer at all --It doesn't take a function and return a function. What kind of dark magic is going on there?
Jeremy Fourna
@jeremyfourna
May 31 2017 14:00

Hello everyone, I can not understand the source of this error when this code is evaluated

R.ifElse(
    R.lte(1, 2),
    R.identity(1),
    Math.round(R.add(R.dec(R.divide(1, 2)), 1))
)

I get every time First argument to _arity must be a non-negative integer no greater than ten, can someone help me ?

Gabe Johnson
@gabejohnson
May 31 2017 14:03
@jeremyfourna the last argument to ifElse should be a function
Jeremy Fourna
@jeremyfourna
May 31 2017 14:03
@gabejohnson I have the same error if I wrap it like this R.identity(Math.round(R.add(R.dec(R.divide(1, 2)), 1)))
or like this () => Math.round(R.add(R.dec(R.divide(1, 2)), 1))
Gabe Johnson
@gabejohnson
May 31 2017 14:05
Also identity is just x => x so you shouldn't be calling it. Do you mean to use http://ramdajs.com/docs/#always
All three arguments to ifElse should be functions
Jeremy Fourna
@jeremyfourna
May 31 2017 14:09
ok thank you for your help
Gabe Johnson
@gabejohnson
May 31 2017 14:09
@jeremyfourna what are you trying to do?
Jeremy Fourna
@jeremyfourna
May 31 2017 14:10
depending on an input if goes through the ifElse
function like this
// defineWidthWithWalls :: number -> number
    function defineWidthWithWalls(originalWidth) {
        // The wall are located every two aisles like this (a = aisle  | = wall) :
        // a : a | a : a | a : a | . : . | . : . | n : n
        return R.ifElse(
            R.lte(originalWidth, 2),
            R.identity(originalWidth),
            Math.round(R.add(R.dec(R.divide(originalWidth, 2)), originalWidth))
        )
    }
with always it works
Gabe Johnson
@gabejohnson
May 31 2017 14:13
    const defineWidthWithWalls =
        // The wall are located every two aisles like this (a = aisle  | = wall) :
        // a : a | a : a | a : a | . : . | . : . | n : n
        R.ifElse(
            R.lte(R.__, 2),
            R.identity,
            R.pipe(R.divide(R.__, 2), R.dec, R.add(???), Math.round)
        );
@jeremyfourna :point_up:
Jeremy Fourna
@jeremyfourna
May 31 2017 14:14
ok thanks
Gabe Johnson
@gabejohnson
May 31 2017 14:15
just edited
Gabe Johnson
@gabejohnson
May 31 2017 14:20
@jeremyfourna you probably want to use http://ramdajs.com/docs/#unless instead of ifElse
Jeremy Fourna
@jeremyfourna
May 31 2017 14:29
I will try different ways
Tom Harding
@i-am-tom
May 31 2017 14:32
const defineWidthWithWalls = x =>
  x + (x < 2 ? 0 : (x / 2 | 0))
Am I being careless?
Jeremy Fourna
@jeremyfourna
May 31 2017 14:33
that works too but I wanted to use all ramda functions lol
Tom Harding
@i-am-tom
May 31 2017 14:34
As long as it’s just as an exercise :eyes: Point-free is often substantially harder to read
Jeremy Fourna
@jeremyfourna
May 31 2017 14:34
I am a small project that I want to refactor in FP style
I have
Tom Harding
@i-am-tom
May 31 2017 14:35
We write lambdas in FP too :(
Jeremy Fourna
@jeremyfourna
May 31 2017 14:35
yes I know, I just wanted to play with all the functions of Ramda
Tom Harding
@i-am-tom
May 31 2017 14:35
Yeah, fair enough
Well, you can jam a converge in there if you go with the second style:
const defineWidthWithWalls =
  converge(add, [
    identity,
    ifElse(lte(2),
      always(0),
      compose(Math.floor, flip(divide)(2)))
  ])
YarnBall
@yarnball
May 31 2017 14:38
Hi all, so I'm liking ramda. I'm using it witch react. However, I want to pass an array of values (from line 22) to work like "AND" filters. I need some help getting the values in the ramda. Any ideas? https://codesandbox.io/s/kRQyqRAPN
Tom Harding
@i-am-tom
May 31 2017 14:40
http://ramdajs.com/docs/#allPass / #anyPass ? Or have I misunderstood?
Julien Bonnin
@JulienBonnin-ABTasty
May 31 2017 14:53
Hello :)
I am trying to figure out the best way in Ramda to loop on an array of objects, and call an attribute of every object iterated on (they all have a "start" method as a property)
Tom Harding
@i-am-tom
May 31 2017 14:53
Probably just R.map(x => x.start()) tbh - you can use invoker if you specifically want to get some extra Ramda involved
Julien Bonnin
@JulienBonnin-ABTasty
May 31 2017 14:55
Thanks for the quick answer, I was using R.map but was wondering if I could get rid of the arrow method inside
Tom Harding
@i-am-tom
May 31 2017 14:55
Then yeah, R.invoker would be the way to go, but I would ask why you want to get rid of the arrow?
Julien Bonnin
@JulienBonnin-ABTasty
May 31 2017 14:55
I am going to look at Invoker then :)
I am quite new to Ramda and found an article suggesting that with Ramda you should try to remove as much parameters as you can
Tom Harding
@i-am-tom
May 31 2017 14:59
Ah. Well, I would say “whatever is most expressive” is probably a better goal. Ramda’s there to help you write clear code, not necessarily overly-curried code :p Use the tools that help you express your intention most clearly, and appreciate that arrow functions are often the answer
e.g. if you weren’t calling the method, just getting the prop, I’d say R.map(R.prop(‘start’)) is a nice, expressive way to write that. However, in true Ramda fashion, there’s a function to do that exact job: R.pluck(‘start’)
Julien Bonnin
@JulienBonnin-ABTasty
May 31 2017 15:04
Thanks you :) Yes I am using R.pluck a lot, coming from Underscore.js I needs some time to get used to Ramda but I can already say I am going to replace my code with it.
Tom Harding
@i-am-tom
May 31 2017 15:04
:)
AKT
@itsakt
May 31 2017 15:43
I have an array of objects like [{id:1,....}, {id:2,...},...] and another array which contains only ids [1,2,6,...] I want to filter first array based on indices from the second array.
any suggestions?
Tom Harding
@i-am-tom
May 31 2017 15:47
As in, filter out everything that doesn’t have an ID in the second array?
AKT
@itsakt
May 31 2017 15:47
yes
Tom Harding
@i-am-tom
May 31 2017 15:48
filter(compose(contains(__, whitelist), prop(‘id’)) ?
Gabe Johnson
@gabejohnson
May 31 2017 15:48
filter(pipe(prop('id'), flip(contains)(ids)))
Kevin Wallace
@kedashoe
May 31 2017 15:51
we've also just added innerJoin
Tom Harding
@i-am-tom
May 31 2017 15:52
These Ramda functions are getting really specialised :p
AKT
@itsakt
May 31 2017 15:52
WOW. I'll try them all. :smile:
Kevin Wallace
@kedashoe
May 31 2017 15:58
@i-am-tom ya adding innerJoin was tied to deprecating intersectionWith which is how it snuck in
Tom Harding
@i-am-tom
May 31 2017 15:58
Aah, hah
Kevin Wallace
@kedashoe
May 31 2017 15:58
also, really enjoy your blog!
Tom Harding
@i-am-tom
May 31 2017 15:59
Oh, thank you! :flushed:
Kevin Wallace
@kedashoe
May 31 2017 15:59
:+1:
YarnBall
@yarnball
May 31 2017 16:12
As no one here has been able to advise, I posted on Stackoverflow. Basically trying to use react and ramda to pass my state for filtering- https://stackoverflow.com/questions/44278193
Tom Harding
@i-am-tom
May 31 2017 17:02
@yarnball I did reply, but you didn’t reply to my reply
Robert Stires
@rjstires
May 31 2017 17:44
Good day all! I was wondering if there were an elegant way of doing the following. I've essentially a tuple, [ConfigObject, RequestObject] and using compose I'd like to update the ConfigObject based on properties of the RequestObject. I was using lenses in a composition but started getting lost down the rabbit hole. Maybe this is something that's been solved already?
Tom Harding
@i-am-tom
May 31 2017 17:45
Uuh, if you swap them round, Pair#extend would be exactly what you want
extend :: Extend w => (w a -> b) -> w a -> w b

pairExtend :: ((m, a) -> b) -> (m, a) -> (m, b)
In other words, you have a function that turns a pair into an updated right-hand value, and extend your original pair with that function
Robert Stires
@rjstires
May 31 2017 17:46
Thanks for the reply Tom, I'm not familiar with that method.
Tom Harding
@i-am-tom
May 31 2017 17:46
idk whether that makes any sense
Robert Stires
@rjstires
May 31 2017 17:47
I'm still struggling to read this style of annotation, give me a tick.
Tom Harding
@i-am-tom
May 31 2017 17:47
It’s the strictly-functional way to use the function updateRight = f => ([a, b]) => [a, f(a, b)]
(which I think is valid JS?)
Robert Stires
@rjstires
May 31 2017 17:48
Is that similar to reduceRight?
Tom Harding
@i-am-tom
May 31 2017 17:49
Uuuh, in a sense, but specifically for pairs
Sorry, I’ve probably confused this issue
Robert Stires
@rjstires
May 31 2017 17:49
JS doesn't support pairs, right?
At least natively?
Tom Harding
@i-am-tom
May 31 2017 17:49
Not really - you have to build a type
but the updateRight function there will work on a 2-elem array
Robert Stires
@rjstires
May 31 2017 17:50
Oh right, Ok I get it. I think that should work than you Tom.
YarnBall
@yarnball
May 31 2017 17:56
@i-am-tom oops didn't realise that was for me. Im' looking to build a reactjs searchkit around Ramda with ANDed & OR queries. anypass is here. Welcoming any feedback https://codesandbox.io/s/xGBJ0pZ8E
performance isn't great on it unfor, a little slow. Thinking i'm not quite usign teh ramda as efficently?
Tom Harding
@i-am-tom
May 31 2017 18:19
It is probably the React; with a list that large that is being kept locally, you might be better doing display:none on the hidden ones rather than removing them from the DOM - will dramatically cut down on interactions
YarnBall
@yarnball
May 31 2017 18:22
how would i implement that @i-am-tom ?
Tom Harding
@i-am-tom
May 31 2017 18:22
Rather than an explicit filter, you just do the check in your main react render loop
YarnBall
@yarnball
May 31 2017 18:29
I see
I'll check into that one, new to react
Tom Harding
@i-am-tom
May 31 2017 18:29
The thing you want to help along is React’s vdom algorithm. It uses the key field to determine whether each element is being added, removed, or updated
SO, if you can keep all the keys there and just change the way they look, you’ll get a faster render because it’s not adding or removing things at the same time
YarnBall
@yarnball
May 31 2017 18:31
I'll try it
But more on ramda, i'm doing return pipe(pluck('genres'), flatten, pluck('name'), uniq)(movies); I want it to make sure the name is unique, but I actually want to return the flatten of 'genres' how would I do that?
Tom Harding
@i-am-tom
May 31 2017 18:31
uniqBy
i.e. pipe(pluck(‘genres’), flatten, uniqBy(prop(‘name’)))
YarnBall
@yarnball
May 31 2017 18:33
oh nice,
Stefano Vozza
@svozza
May 31 2017 18:36
Not 100 per cent sure without seeing your data structure but you can probably save a pass over your array by using chain:
pipe(chain(prop('genres')), uniqBy(prop('name')))
Robert Stires
@rjstires
May 31 2017 18:38
Just wanted to pop back in and thank @i-am-tom (several times over) for updateRight.. Thank you, thank you, and thank you again.
Tom Harding
@i-am-tom
May 31 2017 18:38
Hah! No trouble at all. Thanks for giving me an excuse to preach about Extend :)
YarnBall
@yarnball
May 31 2017 18:39
@i-am-tom could I get a litle more direction on using display none on my react? https://codesandbox.io/s/xGBJ0pZ8E
In my render loop is const filteredResults = andFilter(x, Object.keys(selectedFilters));
Tom Harding
@i-am-tom
May 31 2017 18:46
Yeah so, at the moment, you’re doing renderList = filter(p, fullList)
my suggestion is renderList = map(x => p(x) ? displayBlock(x) : displayNone(x), fullList
i.e. you map instead of filter, and style each one according to your predicate, rather than removing all the ones that don’t match
YarnBall
@yarnball
May 31 2017 18:48
where abouts? I dont see renderList in my code
I may get logged out but ping if you like :)
Tom Harding
@i-am-tom
May 31 2017 18:50
Sorry, I was speaking pseudocode
YarnBall
@yarnball
May 31 2017 18:50
Oh riht
Tom Harding
@i-am-tom
May 31 2017 18:50
andFilter takes a list, and returns a filtered list
YarnBall
@yarnball
May 31 2017 18:50
yep
Tom Harding
@i-am-tom
May 31 2017 18:50
my suggestion is turn andFilter into andPredicate and then use that in a map function at render-time
i.e. just return allPass(wheres)
then in your render, use that resulting predicate to determine how to style each element
YarnBall
@yarnball
May 31 2017 18:53
Right so andFilter(x, Object.keys(selectedFilters)); into andFilter(x => p(x) ? displayBlock(x) : displayNone(x), selectedFilters);? on line 51?