How to use the fluture.encase function in fluture

To help you get started, we’ve selected a few fluture 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 node-gh / gh / src / fp.ts View on Github external
/**
 * © 2013 Liferay, Inc.  and Node GH contributors
 * (see file: README.md)
 * SPDX-License-Identifier: BSD-3-Clause
 */

import * as S from 'sanctuary'
import * as Future from 'fluture'
import * as fs from 'fs'
import * as which from 'which'
import * as $ from 'sanctuary-def'

/* SAFE UTILS */
export const safeWhich = Future.encase(which.sync)
export const safeRealpath = Future.encase(fs.realpathSync)

export function safeImport(
    fileName: string
): Future.FutureInstance {
    let moduleObj = null

    try {
        moduleObj = require(fileName)
    } catch (e) {
        return e.code === 'MODULE_NOT_FOUND' ? Future.of(fileName) : Future.reject(e)
    }

    return Future.of(moduleObj)
}
github node-gh / gh / src / fp.ts View on Github external
/**
 * © 2013 Liferay, Inc.  and Node GH contributors
 * (see file: README.md)
 * SPDX-License-Identifier: BSD-3-Clause
 */

import * as S from 'sanctuary'
import * as Future from 'fluture'
import * as fs from 'fs'
import * as which from 'which'
import * as $ from 'sanctuary-def'

/* SAFE UTILS */
export const safeWhich = Future.encase(which.sync)
export const safeRealpath = Future.encase(fs.realpathSync)

export function safeImport(
    fileName: string
): Future.FutureInstance {
    let moduleObj = null

    try {
        moduleObj = require(fileName)
    } catch (e) {
        return e.code === 'MODULE_NOT_FOUND' ? Future.of(fileName) : Future.reject(e)
    }

    return Future.of(moduleObj)
}

export const safeReaddir = Future.encaseN(fs.readdir)
github Koleok / jest-coverage-ratchet / src / utils.js View on Github external
const takeMaxValues = R.reduce(
  (result, [key, val]) =>
    R.merge(result, { [key]: R.max(result[key] || 0, val) }),
  {}
)

const configPath = ['coverageThreshold', 'global']

//    thresholdLens :: Lens
const thresholdLens = R.lensPath(['jest', ...configPath])

//    ratchetThresholds :: (Object, Object) -> Object
const ratchetThresholds = R.compose(takeMaxValues, R.unnest, R.map(R.toPairs))

//    String -> Future a Error
const requireF = F.encase(require)

//    getConfig :: String -> Future Object Error
const getCurrentThresholdsFromConfig = R.ifElse(
  R.has('jest'),
  R.path(['jest', ...configPath]),
  R.path(configPath)
)

//    getPackageJsonPath :: () -> Future String Error
const getPackageJsonPath = () =>
  F.of(process.cwd()).map(rootDir => resolve(rootDir, 'package.json'))

//    getPackageJson :: () -> Future Object Error
const getPackageJson = () => getPackageJsonPath().chain(requireF)

//    writePackage :: String -> Object -> Future Object Error
github haskellcamargo / js-to-advpl / src / cli.js View on Github external
function cli(args) {
    const { _: [input] } = args
    const ast = readFile(input)
        .chain(Future.encase(parse(_, { sourceType: 'module' })))
        .chain(Future.encase(compileToAdvPL))
    return ast
        .fork(emitError, ({ code }) => console.log(code))
}
github haskellcamargo / js-to-advpl / src / cli.js View on Github external
function cli(args) {
    const { _: [input] } = args
    const ast = readFile(input)
        .chain(Future.encase(parse(_, { sourceType: 'module' })))
        .chain(Future.encase(compileToAdvPL))
    return ast
        .fork(emitError, ({ code }) => console.log(code))
}
github Huemul / chimi / src / lib.js View on Github external
const taskOfSnippets = ({ dependencies, globals, timeout }, glob) =>
  S.pipe(
    [
      S.chain(Future.encase(skip)),
      S.chain(Future.encase(normalizeFiles(dependencies, globals))),
      S.chain(traverseFiles(timeout)),
    ],
    taskify(extract)(glob, ['js', 'javascript'])
  )
github Huemul / chimi / src / lib.js View on Github external
const taskOfSnippets = ({ dependencies, globals, timeout }, glob) =>
  S.pipe(
    [
      S.chain(Future.encase(skip)),
      S.chain(Future.encase(normalizeFiles(dependencies, globals))),
      S.chain(traverseFiles(timeout)),
    ],
    taskify(extract)(glob, ['js', 'javascript'])
  )