How to use the sanctuary-def.Unknown function in sanctuary-def

To help you get started, we’ve selected a few sanctuary-def 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 sanctuary-js / sanctuary / test / internal / sanctuary.js View on Github external
const Sum = require ('./Sum');


//    UnaryType :: String -> String -> Type
const UnaryType = name => typeIdent =>
  $.UnaryType (typeIdent)
              ('')
              ([])
              (x => type (x) === typeIdent)
              (v => [v.value])
              ($.Unknown);

//    env :: Array Type
const env = S.env.concat ([
  UnaryType ('Compose') ('sanctuary/Compose'),
  List.Type ($.Unknown),
  Sum.Type,
]);

module.exports = S.create ({checkTypes: true, env});
github sanctuary-js / sanctuary / test / internal / sanctuary.js View on Github external
const UnaryType = name => typeIdent =>
  $.UnaryType (typeIdent)
              ('')
              ([])
              (x => type (x) === typeIdent)
              (v => [v.value])
              ($.Unknown);
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 / test / signature.spec.js View on Github external
it ('should resolve eithers', () => {
    const env = $.env.concat ([
      S.EitherType ($.Unknown) ($.Unknown),
    ]);
    const {types} = resolve ($) ([]) (env) ('foo :: Either String Number -> String');
    assertTypePairs (S.zip (types) ([S.EitherType ($.String) ($.Number), $.String]));
  });
github xodio / hm-def / test / def.spec.js View on Github external
('someurl')
  (S.is ($.Object))
  (S.keys)
  (S.values);

const $Wrapper = $.UnaryType
  ('Wrapper')
  ('someurl')
  (S.allPass ([S.is ($.Object), hasProp ('value')]))
  (S.pipe ([S.prop ('value'), S.of (Array)]));

const def = create ({
  $,
  checkTypes: true,
  env: $.env.concat ([
    $Map ($.Unknown) ($.Unknown),
    $Wrapper ($.Unknown),
  ]),
  typeClasses: [
    Z.Functor,
    Z.Semigroup,
  ],
});

describe ('def', () => {
  it ('should work with unary functions', () => {
    const foo = def
      ('foo :: Number -> String')
      (x => x.toString ());

    assert.strictEqual (foo (42), '42');
    assert.throws (() => foo (null), 'The value at position 1 is not a member of ‘Number’');