Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reinstate S.unchecked #518

Merged
merged 1 commit into from
Apr 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@
//. });
//. ```
//.
//. Occasionally one may wish to perform an operation which is not type safe,
//. such as mapping over an object with heterogeneous values. This is possible
//. via selective use of [`unchecked`](#unchecked) functions.
//.
//. ## API

(function(f) {
Expand Down Expand Up @@ -404,6 +408,8 @@
(Object.keys (_)).forEach (function(name) {
S[name] = def (name) (_[name].consts) (_[name].types) (_[name].impl);
});
S.unchecked = opts.checkTypes ? create ({checkTypes: false, env: opts.env})
: S;
return S;
}
_.create = {
Expand Down Expand Up @@ -450,6 +456,26 @@
//. . $.ValidNumber ]
//. ```

//# unchecked :: Module
//.
//. A complete Sanctuary module which performs no type checking. This is
//. useful as it permits operations which Sanctuary's type checking would
//. disallow, such as mapping over an object with heterogeneous values.
//.
//. See also [`create`](#create).
//.
//. ```javascript
//. > S.unchecked.map (S.toString) ({x: 'foo', y: true, z: 42})
//. {x: '"foo"', y: 'true', z: '42'}
//. ```
//.
//. Opting out of type checking may cause type errors to go unnoticed.
//.
//. ```javascript
//. > S.unchecked.add (2) ('2')
//. '22'
//. ```

//. ### Classify

//# type :: Any -> { namespace :: Maybe String, name :: String, version :: NonNegativeInteger }
Expand Down
5 changes: 5 additions & 0 deletions test/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ test ('create', function() {
eq (uncheckedDefaultEnv.env) (S.env);
eq (uncheckedCustomEnv.env) (customEnv);

eq (checkedDefaultEnv.unchecked.env) (S.env);
eq (checkedCustomEnv.unchecked.env) (customEnv);
eq (uncheckedDefaultEnv.unchecked.env) (S.env);
eq (uncheckedCustomEnv.unchecked.env) (customEnv);

eq (uncheckedDefaultEnv.add (1) (42)) (S.add (1) (42));
eq (uncheckedDefaultEnv.add (1) ('XXX')) ('1XXX');

Expand Down
15 changes: 15 additions & 0 deletions test/unchecked.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

var S = require ('..');

var eq = require ('./internal/eq');


test ('unchecked', function() {

eq (S.unchecked.add (2) (2)) (4);
eq (S.unchecked.add (2) ('2')) ('22');
eq (S.unchecked.add ('2') (2)) ('22');
eq (S.unchecked.add ('2') ('2')) ('22');

});