Last active
July 30, 2020 09:31
-
-
Save eckelon/06281b735fb9f50443f5c486562ea4e9 to your computer and use it in GitHub Desktop.
Safe side effects using Fluture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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