Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const Sum = require ('./Sum');
// UnaryType :: String -> String -> Type
const UnaryType = name => typeIdent =>
$.UnaryType (typeIdent)
('')
([])
(x => type (x) === typeIdent)
(v => [v.value])
($.Unknown);
// env :: Array Type
const env = S.env.concat ([
UnaryType ('Compose') ('sanctuary/Compose'),
List.Type ($.Unknown),
Sum.Type,
]);
module.exports = S.create ({checkTypes: true, env});
const UnaryType = name => typeIdent =>
$.UnaryType (typeIdent)
('')
([])
(x => type (x) === typeIdent)
(v => [v.value])
($.Unknown);
it ('should resolve maybes', () => {
const Maybe = $.UnaryType
('my-package/Maybe')
('http://example.com/my-package#Maybe')
(S.K (true))
(S.K ([]));
const env = $.env.concat ([
Maybe ($.Unknown),
]);
const {types} = resolve ($) ([]) (env) ('foo :: Maybe String -> String');
assertTypePairs (S.zip (types) ([Maybe ($.String), $.String]));
});
it ('should resolve eithers', () => {
const env = $.env.concat ([
S.EitherType ($.Unknown) ($.Unknown),
]);
const {types} = resolve ($) ([]) (env) ('foo :: Either String Number -> String');
assertTypePairs (S.zip (types) ([S.EitherType ($.String) ($.Number), $.String]));
});
('someurl')
(S.is ($.Object))
(S.keys)
(S.values);
const $Wrapper = $.UnaryType
('Wrapper')
('someurl')
(S.allPass ([S.is ($.Object), hasProp ('value')]))
(S.pipe ([S.prop ('value'), S.of (Array)]));
const def = create ({
$,
checkTypes: true,
env: $.env.concat ([
$Map ($.Unknown) ($.Unknown),
$Wrapper ($.Unknown),
]),
typeClasses: [
Z.Functor,
Z.Semigroup,
],
});
describe ('def', () => {
it ('should work with unary functions', () => {
const foo = def
('foo :: Number -> String')
(x => x.toString ());
assert.strictEqual (foo (42), '42');
assert.throws (() => foo (null), 'The value at position 1 is not a member of ‘Number’');