These are chat archives for ramda/ramda

10th
Apr 2019
1point7point4
@1point7point4
Apr 10 15:28
What's with Ramda's tendency to use var? (i.e. here)
Ben Briggs
@ben-eb
Apr 10 16:45
@1point7point4 Legacy reasons, essentially. https://github.com/ramda/ramda/issues/2337#issuecomment-375403848
1point7point4
@1point7point4
Apr 10 17:53
I don't see any mention of the keyword var or whatnot on that page (the page seems to be more versioning number focused). Is there something I'm not getting?
n-shpilevoy
@n-shpilevoy
Apr 10 17:54

Greetings! I am just starting to get acquainted with functional programming and Ramda in general.
I want to thank the creators and all contributors of this awesome library.

Please, help me rewrite this code in functional style:

const DropdownToggler = document.getElementById('toggle-dropdown');
const DropdownBody = document.getElementById('popup');

DropdownToggler.addEventListener('click', (event) => {

    DropdownBody.classList.toggle('hidden');

    //popper is defined in global scope
    popper && popper.destroy();

    //How instantiate this class with functional approach?
    popper = new Popper(DropdownToggler, DropdownBody, { placement: 'bottom' });
    event.preventDefault();
});

P.S. How to work with a DOM tree using functional programming?

1point7point4
@1point7point4
Apr 10 17:56
One convention is to put backticks ("``") around variable names in comments to help readers distinguish between code and prose. (This isn't specifically an FP thing though)
Also don't mutate global scope, imagine if someone else decided to do the same thing with popper
Rakesh Pai
@rakeshpai
Apr 10 18:01
@n-shpilevoy The DOM itself is very a procedural/imperative API, and is full of side-effects. It's going to be hard to make much of that FP. So, I won't be surprised if the answer to your question is some variation of 'it can't be done'. That said, libs like React do a good job to trying to make the DOM look functional, so that's an option worth considering. If you are to use straight-up DOM manipulation, your code is fine, and while there might be code-golfing suggestions, it's largely fine.
FP would shine in areas like data-processing, for example, where you want to prep your xhr responses before you write it to the DOM, for example.
1point7point4
@1point7point4
Apr 10 18:05
Mutating global scope is bad though, FP or no FP
Ben Briggs
@ben-eb
Apr 10 18:05
1point7point4
@1point7point4
Apr 10 18:06
n-shpilevoy
@n-shpilevoy
Apr 10 18:10
@1point7point4 ,@ben-eb, @rakeshpai, thanks for the explanation
Ben Briggs
@ben-eb
Apr 10 18:11
You're welcome :)
n-shpilevoy
@n-shpilevoy
Apr 10 18:14
I found one recipe in Ramda WIKI dedicated to DOM
Mess with DOM
hp8wvvvgnj6asjm7
@hp8wvvvgnj6asjm7
Apr 10 21:32

Hi there, completely new to FP, done everything OOP by now.
I'm working with streams, basically just infinite streams of numbers from an API. I try to chain the streams and manipulate the data and give it over to the next class and so on, like you would do with a software like reaktor, max msp, or any visual flow based language. Anyone familiar with transducers? Because I now have these three options here: I see Ramda has transducers, i see Reactx js and then i see that we already have Generators in ES6 as a building block. Really confusing for me at this point.

Question is:

If one would build a transducer using Ramda, can we just use the transduce function? Or do ES6 generators make transducers already easy enough? I haven't built one. So i don't even know what I'm talking about exactly.

hp8wvvvgnj6asjm7
@hp8wvvvgnj6asjm7
Apr 10 21:38
i read this article already.. maybe need to read it twice =)
But yes thats exactly what I'm trying to do
Ben Briggs
@ben-eb
Apr 10 21:39
So at the end he explains how to do it in ramda
hp8wvvvgnj6asjm7
@hp8wvvvgnj6asjm7
Apr 10 21:39
What about * generators ?
Also he doesn't seem to use the transduce function from ramda.. was it yet not implemented at that time?
Ben Briggs
@ben-eb
Apr 10 21:42
I don't really have much experience in this area I'm afraid. I came across this article a couple weeks ago and it was a good introduction, but I haven't found a use case that it suits
hp8wvvvgnj6asjm7
@hp8wvvvgnj6asjm7
Apr 10 21:43
np, but agree good article.

Anyone experienced with transducers?

Ben Briggs
@ben-eb
Apr 10 21:53
I think the article uses into at the end because it's more intuitive than transduce(doubleEvens, R.flip(R.append), [], arr)
But YMMV :wink:
hp8wvvvgnj6asjm7
@hp8wvvvgnj6asjm7
Apr 10 21:59
really don't see how to use this example with infinite datastreams