How to use the sanctuary.K 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 xodio / hm-def / src / signature.js View on Github external
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}.`);
      }
    }
  };

  // Helper Type to wipe out thunks
  const Thunk = $.NullaryType ('hm-def/Thunk') ('') (S.K (false));

  //    convertType :: SignatureEntry -> Reader (TypeMap Type)
  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));
github xodio / hm-def / test / signature.spec.js View on Github external
it ('should resolve namespaced user types', () => {
    const Widget = $.NullaryType ('x/y/z/Widget') ('http://example.com/Widget') (S.K (true));
    const env = $.env.concat ([Widget]);
    const {types} = resolve ($) ([]) (env) ('foo :: Widget -> String');
    assert.deepEqual (types, [Widget, $.String]);
  });
github xodio / hm-def / test / signature.spec.js View on Github external
it ('should resolve maybes', () => {
    const Maybe = $.UnaryType
      ('my-package/Maybe')
      ('http://example.com/my-package#Maybe')
      (S.K (true))
      (S.K ([]));

    const env = $.env.concat ([
      Maybe ($.Unknown),
    ]);
    const {types} = resolve ($) ([]) (env) ('foo :: Maybe String -> String');
    assertTypePairs (S.zip (types) ([Maybe ($.String), $.String]));
  });
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));
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));