How to use the sanctuary.map 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 -> 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
[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)
  const convertList = memoize (S.pipe ([
github xodio / hm-def / src / signature.js View on Github external
(types[types.length - 1])
      (types.slice (0, -1))),
  ]));

  //    convertRecordField :: SignatureEntry
  //                          -> Reader (TypeMap (Pair String Type))
  const convertRecordField = memoize (entry => S.pipe ([
    firstChild,
    convertType,
    S.unchecked.map (valueType => [entry.text, valueType]),
  ]) (entry));

  //    convertRecord :: SignatureEntry -> Reader (TypeMap Type)
  const convertRecord = memoize (S.pipe ([
    children,
    S.map (convertRecordField),
    S.unchecked.sequence (Reader),
    S.unchecked.map (fromPairs),
    S.unchecked.map ($.RecordType),
  ]));

  //    convertTypevar :: SignatureEntry -> Type
  const convertTypevar = memoize (x => $.TypeVariable (text (x)));

  //    unaryTypevar :: SignatureEntry -> (Type -> Type)
  const unaryTypevar = memoize (x => $.UnaryTypeVariable (text (x)));

  //    convertConstrainedType :: SignatureEntry -> Reader (TypeMap Type)
  const convertConstrainedType = memoize (entry => S.pipe ([
    firstChild,
    convertType,
    S.unchecked.map (unaryTypevar (entry)),
github Risto-Stevcev / lazy-either / examples / readme2.js View on Github external
  fs.readdir(path, (err, files) => resolve(err ? S.Left(err) : S.Right(S.map(join(path), files)))))
github xodio / hm-def / src / signature.js View on Github external
const constraints = tcm => S.pipe ([
    constraintNames,
    S.map (S.map (lookupTypeClass (tcm))),
  ]);
github plaid / async-problem / synchronous.js View on Github external
const main = () => {
  const path = join (process.argv[2]);
  S.pipe ([path,
           readFile,
           S.lines,
           S.map (path),
           S.map (readFile),
           S.joinWith (''),
           exit0])
         ('index.txt');
};
github plaid / async-problem / synchronous.js View on Github external
const main = () => {
  const path = join (process.argv[2]);
  S.pipe ([path,
           readFile,
           S.lines,
           S.map (path),
           S.map (readFile),
           S.joinWith (''),
           exit0])
         ('index.txt');
};
github xodio / hm-def / src / signature.js View on Github external
const constructType = argTypes => t => {
    assertTypeArity (t) (argTypes);
    switch (t.type) {
      case 'BINARY':
        return fromBinaryType (t) (argTypes[0]) (argTypes[1]);
      case 'UNARY':
        return fromUnaryType (t) (argTypes[0]);
      default: {
        throw new TypeError (`Type ${t.name} should be recreated with `
          + `Types: ${S.map (name, argTypes)} but it haven't got `
          + `a proper function recreator for type ${t.type}.`);
      }
    }
  };
github plaid / async-problem / async.js View on Github external
readFile (path ('index.txt')) ((err, data) => {
    if (err != null) exit1 (err);
    async.map (
      S.map (path) (S.lines (data)),
      (filename, callback) => readFile (filename) (callback),
      (err, results) => {
        if (err == null) exit0 (S.joinWith ('') (results)); else exit1 (err);
      }
    );
  });
};