How to use the sanctuary-def.RegExp 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 / 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);

});