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

update S.env to reference the module's environment #524

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
50 changes: 26 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,15 @@
var Cons = (__doctest.require ('./test/internal/List')).Cons;
var Sum = __doctest.require ('./test/internal/Sum');
var S = (function(S) {
return S.create ({
var S_ = S.create ({
checkTypes: true,
env: S.env.concat ([
(__doctest.require ('./test/internal/List')).Type ($.Unknown),
Sum.Type
])
});
S_.env = S.env; // see S.env doctest
return S_;
} (require ('.')));
/* eslint-enable no-unused-vars */
}
Expand Down Expand Up @@ -336,25 +338,6 @@
})
(K ([]));

// defaultEnv :: Array Type
var defaultEnv = Z.concat ($.env, [
$.FiniteNumber,
$.NonZeroFiniteNumber,
$Either ($.Unknown) ($.Unknown),
Fn ($.Unknown) ($.Unknown),
$.GlobalRegExp,
$.NonGlobalRegExp,
$.Integer,
$.NonNegativeInteger,
$Maybe ($.Unknown),
$.Array2 ($.Unknown) ($.Unknown),
$.RegexFlags,
$.Type,
$.TypeClass,
$.ValidDate,
$.ValidNumber
]);

// Options :: Type
var Options = $.RecordType ({checkTypes: $.Boolean, env: $.Array ($.Any)});

Expand Down Expand Up @@ -413,7 +396,7 @@
function create(opts) {
var def = $.create (opts);
var S = {
env: defaultEnv,
env: opts.env,
is: def ('is') ({}) ([$.Type, $.Any, $.Boolean]) ($.test (opts.env)),
MaybeType: $Maybe,
Maybe: Maybe,
Expand All @@ -434,8 +417,8 @@

//# env :: Array Type
//.
//. The default environment, which may be used as is or as the basis of a
//. custom environment in conjunction with [`create`](#create).
//. The Sanctuary module's environment (`(S.create ({checkTypes, env})).env`
//. is a reference to `env`). Useful in conjunction with [`create`](#create).
//.
//. ```javascript
//. > S.env
Expand Down Expand Up @@ -5152,7 +5135,26 @@
impl: splitOnRegex
};

return create ({checkTypes: true, env: defaultEnv});
return create ({
checkTypes: true,
env: Z.concat ($.env, [
$.FiniteNumber,
$.NonZeroFiniteNumber,
$Either ($.Unknown) ($.Unknown),
Fn ($.Unknown) ($.Unknown),
$.GlobalRegExp,
$.NonGlobalRegExp,
$.Integer,
$.NonNegativeInteger,
$Maybe ($.Unknown),
$.Array2 ($.Unknown) ($.Unknown),
$.RegexFlags,
$.Type,
$.TypeClass,
$.ValidDate,
$.ValidNumber
])
});

}));

Expand Down
5 changes: 5 additions & 0 deletions test/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ test ('create', function() {
eq (S.sort (Object.keys (uncheckedDefaultEnv))) (expected);
eq (S.sort (Object.keys (uncheckedCustomEnv))) (expected);

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

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

Expand Down