How to use the sanctuary-def.Number 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 / is.js View on Github external
eq (S.is ($.Either ($.String) ($.Integer)) (S.Right (''))) (false);
  eq (S.is ($.Either ($.String) ($.Integer)) (S.Left (''))) (true);
  eq (S.is ($.Either ($.String) ($.Integer)) (S.Right (0))) (true);

  const a = $.TypeVariable ('a');

  eq (S.is ($.Array (a)) ([])) (true);
  eq (S.is ($.Array (a)) ([1, 2, 3])) (true);
  eq (S.is ($.Array (a)) (['foo', 'bar', 'baz'])) (true);
  eq (S.is ($.Array (a)) (['foo', true, 42])) (false);
  eq (S.is ($.Array (a)) ([Sum (1), Sum (2), Sum (3)])) (false);

  eq ((S.create ({checkTypes: true, env: []})).is ($.Array (a)) ([])) (false);
  eq ((S.create ({checkTypes: true, env: [$.String]})).is ($.Array (a)) ([])) (true);
  eq ((S.create ({checkTypes: true, env: [$.String]})).is ($.Array (a)) ([1, 2, 3])) (false);
  eq ((S.create ({checkTypes: true, env: [$.Number]})).is ($.Array (a)) ([1, 2, 3])) (true);
  eq ((S.create ({checkTypes: true, env: [Sum.Type]})).is ($.Array (a)) ([Sum (1), Sum (2), Sum (3)])) (true);

});
github sanctuary-js / sanctuary / test / gets.js View on Github external
test ('gets', () => {

  eq (S.show (S.gets)) ('gets :: (Any -> Boolean) -> Array String -> a -> Maybe b');

  eq (S.gets (S.is ($.Number)) (['x']) ({x: {z: 0}, y: 42})) (S.Nothing);
  eq (S.gets (S.is ($.Number)) (['y']) ({x: {z: 0}, y: 42})) (S.Just (42));
  eq (S.gets (S.is ($.Number)) (['z']) ({x: {z: 0}, y: 42})) (S.Nothing);
  eq (S.gets (S.is ($.Number)) (['x', 'z']) ({x: {z: 0}, y: 42})) (S.Just (0));
  eq (S.gets (S.is ($.Number)) (['a', 'b', 'c']) ({x: {z: 0}, y: 42})) (S.Nothing);
  eq (S.gets (S.is ($.Number)) ([]) ({x: {z: 0}, y: 42})) (S.Nothing);
  eq (S.gets (S.is ($.Object)) ([]) ({x: {z: 0}, y: 42})) (S.Just ({x: {z: 0}, y: 42}));
  eq (S.gets (S.is ($.RegExp)) (['x']) ({x: vm.runInNewContext ('/.*/')})) (S.Just (/.*/));

  eq (S.gets (S.K (true)) (['valueOf']) (null)) (S.Nothing);
  eq (S.gets (S.K (true)) (['valueOf']) (undefined)) (S.Nothing);

  eq (S.gets (S.is ($.Array ($.Number))) (['x']) ({x: [1, 2]})) (S.Just ([1, 2]));
  eq (S.gets (S.is ($.Array ($.Number))) (['x']) ({x: [1, 2, null]})) (S.Nothing);

});
github sanctuary-js / sanctuary / test / get.js View on Github external
test ('get', () => {

  eq (S.show (S.get)) ('get :: (Any -> Boolean) -> String -> a -> Maybe b');

  eq (S.get (S.is ($.Number)) ('x') ({x: 0, y: 42})) (S.Just (0));
  eq (S.get (S.is ($.Number)) ('y') ({x: 0, y: 42})) (S.Just (42));
  eq (S.get (S.is ($.Number)) ('z') ({x: 0, y: 42})) (S.Nothing);
  eq (S.get (S.is ($.String)) ('z') ({x: 0, y: 42})) (S.Nothing);
  eq (S.get (S.is ($.String)) ('x') ({x: 0, y: 42})) (S.Nothing);
  eq (S.get (S.is ($.RegExp)) ('x') ({x: vm.runInNewContext ('/.*/')})) (S.Just (/.*/));

  eq (S.get (S.K (true)) ('valueOf') (null)) (S.Nothing);
  eq (S.get (S.K (true)) ('valueOf') (undefined)) (S.Nothing);

  eq (S.get (S.is ($.Array ($.Number))) ('x') ({x: [1, 2]})) (S.Just ([1, 2]));
  eq (S.get (S.is ($.Array ($.Number))) ('x') ({x: [1, 2, null]})) (S.Nothing);

});
github sanctuary-js / sanctuary / test / MaybeType.js View on Github external
test ('MaybeType', () => {

  eq (typeof S.MaybeType) ('function');
  eq (S.MaybeType.length) (1);
  eq (S.show (S.MaybeType)) ('Maybe :: Type -> Type');

  eq (S.is (S.MaybeType ($.Number)) (S.Nothing)) (true);
  eq (S.is (S.MaybeType ($.Number)) (S.Just (42))) (true);
  eq (S.is (S.MaybeType ($.Number)) (S.Just ('42'))) (false);
  eq (S.is (S.MaybeType ($.Number)) (S.Right (42))) (false);
  eq (S.is (S.MaybeType ($.Number)) (null)) (false);

});
github sanctuary-js / sanctuary / test / gets.js View on Github external
test ('gets', () => {

  eq (S.show (S.gets)) ('gets :: (Any -> Boolean) -> Array String -> a -> Maybe b');

  eq (S.gets (S.is ($.Number)) (['x']) ({x: {z: 0}, y: 42})) (S.Nothing);
  eq (S.gets (S.is ($.Number)) (['y']) ({x: {z: 0}, y: 42})) (S.Just (42));
  eq (S.gets (S.is ($.Number)) (['z']) ({x: {z: 0}, y: 42})) (S.Nothing);
  eq (S.gets (S.is ($.Number)) (['x', 'z']) ({x: {z: 0}, y: 42})) (S.Just (0));
  eq (S.gets (S.is ($.Number)) (['a', 'b', 'c']) ({x: {z: 0}, y: 42})) (S.Nothing);
  eq (S.gets (S.is ($.Number)) ([]) ({x: {z: 0}, y: 42})) (S.Nothing);
  eq (S.gets (S.is ($.Object)) ([]) ({x: {z: 0}, y: 42})) (S.Just ({x: {z: 0}, y: 42}));
  eq (S.gets (S.is ($.RegExp)) (['x']) ({x: vm.runInNewContext ('/.*/')})) (S.Just (/.*/));

  eq (S.gets (S.K (true)) (['valueOf']) (null)) (S.Nothing);
  eq (S.gets (S.K (true)) (['valueOf']) (undefined)) (S.Nothing);

  eq (S.gets (S.is ($.Array ($.Number))) (['x']) ({x: [1, 2]})) (S.Just ([1, 2]));
  eq (S.gets (S.is ($.Array ($.Number))) (['x']) ({x: [1, 2, null]})) (S.Nothing);

});
github sanctuary-js / sanctuary / test / parseJson.js View on Github external
test ('parseJson', () => {

  eq (S.show (S.parseJson)) ('parseJson :: (Any -> Boolean) -> String -> Maybe a');

  eq (S.parseJson (S.is ($.Any)) ('[Invalid JSON]')) (S.Nothing);
  eq (S.parseJson (S.is ($.Array ($.Any))) ('{"foo":"bar"}')) (S.Nothing);
  eq (S.parseJson (S.is ($.Array ($.Any))) ('["foo","bar"]')) (S.Just (['foo', 'bar']));
  eq (S.parseJson (S.is ($.Array ($.Number))) ('[1,2]')) (S.Just ([1, 2]));
  eq (S.parseJson (S.is ($.Array ($.Number))) ('[1,2,null]')) (S.Nothing);

});
github sanctuary-js / sanctuary / test / MaybeType.js View on Github external
test ('MaybeType', () => {

  eq (typeof S.MaybeType) ('function');
  eq (S.MaybeType.length) (1);
  eq (S.show (S.MaybeType)) ('Maybe :: Type -> Type');

  eq (S.is (S.MaybeType ($.Number)) (S.Nothing)) (true);
  eq (S.is (S.MaybeType ($.Number)) (S.Just (42))) (true);
  eq (S.is (S.MaybeType ($.Number)) (S.Just ('42'))) (false);
  eq (S.is (S.MaybeType ($.Number)) (S.Right (42))) (false);
  eq (S.is (S.MaybeType ($.Number)) (null)) (false);

});