Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test ('Functor', () => {
eq (Z.Functor.test (Left (Useless))) (true);
eq (Z.Functor.test (Right (Useless))) (true);
});
test ('Functor', () => {
eq (Z.Functor.test (Nothing)) (true);
eq (Z.Functor.test (Just (Useless))) (true);
});
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’');
});
it ('should work with thunks', () => {
const foo = def
test ('Functor', () => {
eq (Z.Functor.test (Identity (Useless))) (true);
});
test ('Functor', () => {
eq (Z.Functor.test (Left (Useless))) (true);
eq (Z.Functor.test (Right (Useless))) (true);
});
it ('should resolve constraints', () => {
const a = $.TypeVariable ('a');
const b = $.TypeVariable ('b');
const f = $.UnaryTypeVariable ('f');
const tcs = [Z.Functor];
const {types} = resolve ($) (tcs) ($.env) ('foo :: Functor f => (a -> b) -> f a -> f b');
assertTypePairs (S.zip (types) ([$.Function ([a, b]), f (a), f (b)]));
});
});
test ('Functor', () => {
eq (Z.Functor.test (Nothing)) (true);
eq (Z.Functor.test (Just (Useless))) (true);
});
function map$mapper(mapper, m){
if(!Z.Functor.test(m)) throwInvalidArgument('Future.map', 1, 'be a Functor', m);
return Z.map(mapper, m);
}
composition: assert.forall3 (function(u, f, g) {
return Z.Functor.test (u) &&
equals (map (compose (f) (g)) (u),
compose (map (f)) (map (g)) (u));
})
identity: assert.forall1 (function(u) {
return Z.Functor.test (u) &&
equals (map (identity) (u),
u);
}),