const IO = f => ({
runIO: f,
map: g =>
IO(() => g(f())),
chain: g =>
IO(g(f()).runIO)
})
const log = label => x =>
IO(() => (console.log(label, x), x))
const $ = x =>
IO(() => document.querySelector(x))
const getText = e =>
e.textContent
const main = selector =>
$(selector)
.map(getText)
.chain(log('A'))
.map(s => s.toUpperCase())
.chain(log('B'))
.runIO()
main('title')
// A hello world
// B HELLO WORLD