Skip to content

Instantly share code, notes, and snippets.

@eckelon
Last active July 30, 2020 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eckelon/06281b735fb9f50443f5c486562ea4e9 to your computer and use it in GitHub Desktop.
Save eckelon/06281b735fb9f50443f5c486562ea4e9 to your computer and use it in GitHub Desktop.
Safe side effects using Fluture
// test in: https://runkit.com/eckelon/5f22785767e514001bddd5e3
const { env } = require('sanctuary-def');
const S = require('sanctuary');
const {env : flutureEnv} = require('fluture-sanctuary-types');
const { encase, fork } = require('fluture');
const { pipe, I } = S.create ({checkTypes: true, env: S.env.concat (flutureEnv)});
function Logger() {
this._log = (level) => (message) => {
const foo = 1;
foo.split('3'); // what if we force an error
console.log(`[LOG ${level}] - ${message}`);
};
this.info = this._log('INFO');
this.error = this._log('ERROR');
}
const logger = new Logger();
const logInfo = encase(logger.info);
pipe([
logInfo
, fork((reason) => console.error(`Error in logger: ${reason}`))(I)
])('hola')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment