How to use the sanctuary.either function in sanctuary

To help you get started, we’ve selected a few sanctuary examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Risto-Stevcev / lazy-either / examples / readme2.js View on Github external
//:: String -> LazyEither (Either e [String])
const ls = path => LazyEither(resolve =>
  fs.readdir(path, (err, files) => resolve(err ? S.Left(err) : S.Right(S.map(join(path), files)))))

//:: String -> LazyEither (Either e String)
const cat = file => LazyEither(resolve =>
  fs.readFile(file, {encoding: 'utf8'}, (err, data) => resolve(err ? S.Left(err) : S.Right(data))))

//:: String -> LazyEither (Either e String)
const catDir =
S.pipe([ls,
        S.chain(S.traverse(LazyEither, cat)),
        S.map(S.unlines)])

// A LazyEither instance is executed when value gets called:
catDir(os.homedir()).value(S.either(console.error, console.log))
github Risto-Stevcev / lazy-either / src / either.js View on Github external
return new LazyEither(resolve => {
    self._value(S.compose(resolve, S.either(leftFn, rightFn)))
  })
}
github Risto-Stevcev / lazy-either / src / either.js View on Github external
return new LazyEither(resolve => {
    self._value(S.either(a => resolve(S.Left(a)), b => f(b)._value(resolve)))
  })
}