How to use the sanctuary-def.Array 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.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 / 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 / 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 / gets.js View on Github external
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 xodio / hm-def / test / signature.spec.js View on Github external
it ('should resolve lists', () => {
    const {types} = resolve ($) ([]) ($.env) ('foo :: [Number] -> [String]');
    const expecteds = [$.Array ($.Number), $.Array ($.String)];

    const lists = S.zip (types) (expecteds);
    assertTypePairs (lists);
  });
github xodio / hm-def / src / index.js View on Github external
import $priv from 'sanctuary-def';
import * as Sig from './signature';

const def = $priv.create ({checkTypes: true, env: $priv.env});

const Parameters = $priv.RecordType ({
  $: $priv.Object,
  checkTypes: $priv.Boolean,
  env: $priv.Array ($priv.Type),
  typeClasses: $priv.Array ($priv.TypeClass),
});

export const create = def
  ('create')
  ({})
  ([
    Parameters,
    $priv.String,
    $priv.AnyFunction,
    $priv.AnyFunction,
  ])
  (({$, checkTypes, env, typeClasses}) => {
    const $def = $.create ({checkTypes, env});
    const resovleSig = Sig.resolve ($) (typeClasses) (env);

    return $def