How to use the sanctuary.curry2 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 plaid / async-problem / common / join.js View on Github external
'use strict';

const path          = require ('path');

const S             = require ('sanctuary');

//  join :: String -> String -> String
module.exports = S.curry2 (path.join);
github Risto-Stevcev / lazy-either / examples / readme2.js View on Github external
'use strict'
const LazyEither = require('..')
const fs = require('fs')
    , os = require('os')
    , path = require('path')
    , R  = require('ramda')
    , S  = require('sanctuary')

//:: String -> String -> String
const join = S.curry2(path.join)

//:: 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:
github node-gh / gh / src / logger.ts View on Github external
console.log(...args)
        return
    }

    console.log('DEBUG:', ...args)
}

export function insane(...args) {
    if (!process.env.GH_VERBOSE_INSANE) {
        return
    }

    console.log(...args)
}

export const exitWithError = S.curry2((message, stack) => {
    if (process.env.GH_VERBOSE || process.env.GH_VERBOSE_INSANE) {
        console.error(`${message}\n${stack}`)
    } else {
        console.error(message)
    }

    process.exit(1)
})

export function error(...args) {
    if (typeof args[0] === 'string') {
        args[0] = `fatal: ${args[0]}`
    }

    console.error(...args)
    process.exit(1)
github Risto-Stevcev / lazy-either / examples / vs-future1.js View on Github external
const join = S.curry2(path.join)

const readDir = path =>
  new LazyEither(resolve => {
    fs.readdir(path,
               (err, files) => resolve(err != null ? S.Left(err) : S.Right(S.map(join(path), files))))
  })

const readFile = path =>
  new LazyEither(resolve => {
    fs.readFile(path,
                {encoding: 'utf8'},
                (err, data) => resolve(err != null ? S.Left(err) : S.Right(data)))
  })

const writeFile = S.curry2((file, data) =>
  new LazyEither(resolve => {
    fs.writeFile(file,
                 data,
                 err => resolve(err != null ? S.Left(err) : S.Right('Write successful')))
  })
)

const getStats =
S.pipe([readDir,
        S.map(S.filter(S.test(/[.]js$/))),
        S.chain(S.traverse(LazyEither, readFile)),
        S.map(String),
        S.map(S.matchAll(/require[(][^)]+[)]/g)),
        S.map(S.prop('length')),
        S.map(String),
        S.map(S.concat('Total requires: ')),
github Risto-Stevcev / lazy-either / examples / vs-future1.js View on Github external
'use strict'
const R  = require('ramda')
    , S  = require('sanctuary')
    , fs = require('fs')
    , os = require('os')
    , path = require('path')
const LazyEither = require('..')

const join = S.curry2(path.join)

const readDir = path =>
  new LazyEither(resolve => {
    fs.readdir(path,
               (err, files) => resolve(err != null ? S.Left(err) : S.Right(S.map(join(path), files))))
  })

const readFile = path =>
  new LazyEither(resolve => {
    fs.readFile(path,
                {encoding: 'utf8'},
                (err, data) => resolve(err != null ? S.Left(err) : S.Right(data)))
  })

const writeFile = S.curry2((file, data) =>
  new LazyEither(resolve => {
github voorhoede / playbook / src / main.js View on Github external
const {
  chain,
  curry2,
  compose,
  gets,
  match,
  map,
  Nothing,
  prop,
  pipe,
  reduce,
} = require('sanctuary');

const foldersToPath = pipe([
  map (compose (kebabCaseIt) (prop('name')) ),
  reduce (curry2(path.join)) (''),
]);

const isPermissionError = pipe([
  gets (Boolean) (['body', 'error_summary']),
  chain(match(/insufficient_permissions/)),
]);

const fetchPaginatedDocIds = apiFetch => previousDocIds => ({
  body: { doc_ids: docIds, cursor, has_more: hasMore },
}) =>
  hasMore
    ? apiFetch('/docs/list/continue', {
      body: { cursor },
    })
      .then(fetchPaginatedDocIds (apiFetch) (previousDocIds.concat(docIds)))
    : previousDocIds.concat(docIds);