const Future = require('fluture') // I can't guarantee this will work out of the box - it's quite old... but // you should hopefully be able to see how this fits together! const { ReaderT } = require('fantasy-readers') // First of all, you're going to need to "lift" all your `Future` operations // to work within ReaderT. Basically, you just need to call `ReaderT.lift` on // any `Future` values. const doAjaxThing_ = x => ReaderT.lift(doAjaxThing(x)) const doOtherThing_ = x => y => ReaderT.lift(doOtherThing(x)(y)) // A little app that calls `doOtherThing_` with the result of `doAjaxThing_` and // your global config. It's "ReaderT Config (Future Error Result)" const app = doAjaxThing_ .chain(stuff => ReaderT.ask // Here, we just "ask" for the config! .chain(config => doOtherThing_(stuff)(config))) // Future Error Result (production app) const appOnProduction = app.run(prodConfig) // Future Error Result (development app) const appOnDevelopment = app.run(devConfig) // Run as usual :) appOnProduction .fork( e => console.error(e) , x => console.log(x) )