monet / monet.js

monet.js - Monadic types library for JavaScript
https://monet.github.io/monet.js/
MIT License
1.6k stars 114 forks source link

Is it wrong to call "run()" two times in a row? #253

Open Djordjenp opened 2 years ago

Djordjenp commented 2 years ago

Hello I'm trying to get element from the DOM and set it's text content, I managed to make it work, but the way I did it doesn't seem right to me

const getElement = id => IO(() => document.querySelector(id))
const setElementText = element => text => IO(() => element.textContent = text)

getElement('h1').map(setElementText).run()('New Title').run() // it works

I am calling "run()" twice and I believe it should be called once. Btw I know I can just swap argument position in "setElementText" function so I accept "text" first then "element" then I would be able to call "run()" once and it would work. But I am interested is there a better solution for example above.