How to use the sanctuary.pipe 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
, 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:
catDir(os.homedir()).value(S.either(console.error, console.log))
github xodio / hm-def / src / signature.js View on Github external
const convertType = memoize (entry => cond ([
      [typeEq ('typeConstructor'), convertTypeConstructor],
      [typeEq ('function'), convertFunction],
      [typeEq ('list'), convertList],
      [typeEq ('record'), convertRecord],
      [typeEq ('constrainedType'), convertConstrainedType],
      [typeEq ('typevar'), S.pipe ([convertTypevar, Reader.of])],
      [typeEq ('thunk'), S.K (Reader.of (Thunk))],
      [S.K (true), e => {
        throw new Error
          (`Don't know what to do with signature entry ${e.type}`);
      }],
    ]) (entry));

  //    convertTypes :: Array SignatureEntry -> Reader (TypeMap (Array Type))
  const convertTypes = memoize (S.pipe ([
      S.map (convertType),
      S.unchecked.sequence (Reader),
      S.unchecked.map (S.reject (S.equals (Thunk))),
    ]));

  //    convertTypeConstructor :: SignatureEntry -> Reader (TypeMap Type)
  const convertTypeConstructor = memoize (S.ifElse
    (hasChildren)
    (y => S.pipe ([
      children,
      convertTypes,
      x => S.unchecked.lift2 (constructType) (x) (lookupType (y)),
    ]) (y))
    (lookupType));

  //    convertList :: SignatureEntry -> Reader (TypeMap Type)
github Risto-Stevcev / lazy-either / examples / vs-future1.js View on Github external
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: ')),
        S.chain(writeFile('stats.txt'))])

getStats(__dirname).value(console.log)
//getStats('blablah').value(console.log)
github voorhoede / playbook / src / fetch-papers.js View on Github external
content: {
        metaData,
      },
      location,
    }))
  ));
});

fetchAllDocIds()
  .then(docIds => docIds.reduce((docs, id) => ({
    ...docs,
    [id]: fetchDocFolders(id),
  }), {}))
  .then(promiseAllProps)
  .then(justs)
  .then(filter (pipe([
    map(prop('id')),
    elem(process.env.DROPBOX_PAPER_DIRECTORY_ID),
  ])))
  .then(Object.entries)
  .then(appendMetaData)
  .then(reject(isDeletedDoc))
  .then(appendDocContent)
  .then(saveDocsLocally)
  .catch(console.error);
github voorhoede / playbook / src / main.js View on Github external
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);

const fetchAllDocIds = apiFetch => () => apiFetch('/docs/list', {})
  .then(fetchPaginatedDocIds (apiFetch) ([]));
github voorhoede / playbook / docs / .vuepress / config.js View on Github external
const documentsMetaData = require('../meta-tree.json');
const generateSidebar = require('../../src/generate-sidebar.js');
const urlMatchers = require('../../src/url-matchers.js');

const {
  chain,
  compose,
  find,
  pipe,
  prop,
  map,
  match,
} = require('sanctuary');

const getDropboxDocumentLocation = pipe([
  match(/paper\.dropbox\.com\/doc\/.+--\S{26}-(\w{21})/),
  chain(match => match.groups[0]),
  chain(urlId => find (doc => doc.id === urlId) (documentsMetaData)),
  map(compose (path.parse) (prop('location'))),
]);

module.exports = {
  title: 'Playbook',
  themeConfig: {
    sidebar: generateSidebar(documentsMetaData),
  },
  extendMarkdown: markdown => {
    markdown.use(markdownItForInline, 'internal-link', 'link_open', (tokens, index) => {
      const token = tokens[index];

      pipe([
github voorhoede / playbook / src / url-matchers.js View on Github external
'use strict';

const { chain, match, pipe } = require('sanctuary');

const getYoutubeUrlId = pipe([
  match(/^https:\/\/w*\.*youtube\.com\/watch\?v=(\w{11})/),
  chain(match => match.groups[0]),
]);

const getYoutubePlaylistUrlId = pipe([
  match(/^https:\/\/w*\.*youtube\.com\/playlist\?list=([\w\d-]+)/),
  chain(match => match.groups[0]),
]);

module.exports = {
  getYoutubeUrlId,
  getYoutubePlaylistUrlId,
};
github xodio / hm-def / src / signature.js View on Github external
  const convertRecordField = memoize (entry => S.pipe ([
    firstChild,
    convertType,
    S.unchecked.map (valueType => [entry.text, valueType]),
  ]) (entry));
github voorhoede / playbook / src / main.js View on Github external
const { kebabCaseIt } = require('case-it');

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 },
    })
github plaid / async-problem / promises-ramda.js View on Github external
const concatFiles = dir =>
  S.pipe([join(R.__, 'index.txt'),
          readFile({encoding: 'utf8'}),
          then(S.lines),
          then(R.map(join(dir))),
          then(R.map(readFile({encoding: 'utf8'}))),
          then(Promise.all),
          then(R.join(''))],
         dir);