Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import $ from 'sanctuary-def';
import Z from 'sanctuary-type-classes';
import Future from 'fluture';
import FutureTypes from 'fluture-sanctuary-types';
const S = Sanctuary.create ({
checkTypes: process.env.NODE_ENV !== 'production',
env: Sanctuary.env.concat (FutureTypes.env)
});
const def = $.create ({
checkTypes: process.env.NODE_ENV !== 'production',
env: $.env.concat (FutureTypes.env)
});
$.a = $.TypeVariable ('a');
$.b = $.TypeVariable ('b');
$.Either = S.EitherType;
$.Maybe = S.MaybeType;
$.Future = FutureTypes.FutureType;
// Extensions
S.chainRej = S.curry2 ((fn, future) => future.chainRej (fn));
S.replace = S.curry3((key, replacement, str) => str.replace (key, replacement));
S.lift4 = S.curry4 ((fn, a1, a2, a3, a4) => Z.ap (Z.ap (Z.ap (Z.map (fn, a1), a2), a3), a4));
S.eitherToFuture = S.either (Future.reject) (Future.of);
S.invoke = fnName => arg => obj => obj[fnName] (arg);
export {
$,
S,
def,
import Z from 'sanctuary-type-classes';
import Future from 'fluture';
import FutureTypes from 'fluture-sanctuary-types';
const S = Sanctuary.create ({
checkTypes: process.env.NODE_ENV !== 'production',
env: Sanctuary.env.concat (FutureTypes.env)
});
const def = $.create ({
checkTypes: process.env.NODE_ENV !== 'production',
env: $.env.concat (FutureTypes.env)
});
$.a = $.TypeVariable ('a');
$.b = $.TypeVariable ('b');
$.Either = S.EitherType;
$.Maybe = S.MaybeType;
$.Future = FutureTypes.FutureType;
// Extensions
S.chainRej = S.curry2 ((fn, future) => future.chainRej (fn));
S.replace = S.curry3((key, replacement, str) => str.replace (key, replacement));
S.lift4 = S.curry4 ((fn, a1, a2, a3, a4) => Z.ap (Z.ap (Z.ap (Z.map (fn, a1), a2), a3), a4));
S.eitherToFuture = S.either (Future.reject) (Future.of);
S.invoke = fnName => arg => obj => obj[fnName] (arg);
export {
$,
S,
def,
Future
eq (S.is ($.Array ($.Integer)) ([1, 2, 3])) (true);
eq (S.is ($.Array ($.Integer)) ([])) (true);
eq (S.is ($.Maybe ($.Integer)) (S.Nothing)) (true);
eq (S.is ($.Maybe ($.Integer)) (S.Just (0))) (true);
eq (S.is ($.Maybe ($.Integer)) (S.Left (0))) (false);
eq (S.is ($.Maybe ($.Integer)) (S.Right (0))) (false);
eq (S.is ($.Either ($.String) ($.Integer)) (S.Nothing)) (false);
eq (S.is ($.Either ($.String) ($.Integer)) (S.Just (0))) (false);
eq (S.is ($.Either ($.String) ($.Integer)) (S.Left (0))) (false);
eq (S.is ($.Either ($.String) ($.Integer)) (S.Right (''))) (false);
eq (S.is ($.Either ($.String) ($.Integer)) (S.Left (''))) (true);
eq (S.is ($.Either ($.String) ($.Integer)) (S.Right (0))) (true);
const a = $.TypeVariable ('a');
eq (S.is ($.Array (a)) ([])) (true);
eq (S.is ($.Array (a)) ([1, 2, 3])) (true);
eq (S.is ($.Array (a)) (['foo', 'bar', 'baz'])) (true);
eq (S.is ($.Array (a)) (['foo', true, 42])) (false);
eq (S.is ($.Array (a)) ([Sum (1), Sum (2), Sum (3)])) (false);
eq ((S.create ({checkTypes: true, env: []})).is ($.Array (a)) ([])) (false);
eq ((S.create ({checkTypes: true, env: [$.String]})).is ($.Array (a)) ([])) (true);
eq ((S.create ({checkTypes: true, env: [$.String]})).is ($.Array (a)) ([1, 2, 3])) (false);
eq ((S.create ({checkTypes: true, env: [$.Number]})).is ($.Array (a)) ([1, 2, 3])) (true);
eq ((S.create ({checkTypes: true, env: [Sum.Type]})).is ($.Array (a)) ([Sum (1), Sum (2), Sum (3)])) (true);
});
it ('should resolve typevars', () => {
const a = $.TypeVariable ('a');
const b = $.TypeVariable ('b');
const {types} = resolve ($) ([]) ($.env) ('foo :: a -> b -> a');
S.zip (types) ([a, b, a]).forEach (pair => {
const actual = S.fst (pair);
const expected = S.snd (pair);
assert.equal (actual.name, expected.name);
assert.equal (actual.type, expected.type);
assert.deepEqual (actual.keys, expected.keys);
assert.deepEqual (actual.types, expected.types);
});
});
it ('should resolve typevars', () => {
const a = $.TypeVariable ('a');
const b = $.TypeVariable ('b');
const {types} = resolve ($) ([]) ($.env) ('foo :: a -> b -> a');
S.zip (types) ([a, b, a]).forEach (pair => {
const actual = S.fst (pair);
const expected = S.snd (pair);
assert.equal (actual.name, expected.name);
assert.equal (actual.type, expected.type);
assert.deepEqual (actual.keys, expected.keys);
assert.deepEqual (actual.types, expected.types);
});
});
const $ = require('sanctuary-def')
const a = $.TypeVariable('a')
const b = $.TypeVariable('b')
const $IO = $.UnaryType(
'future-io/IO',
(x) => x && x['@@type'] === 'future-io/IO',
() => []
)
const $Task = $.UnaryType(
'Task',
(x) => x && typeof x.fork === 'function',
() => []
)
const env = $.env.concat([
$IO,
$Task
])
const def = $.create({ checkTypes: true, env })
const $ = require('sanctuary-def')
const a = $.TypeVariable('a')
const b = $.TypeVariable('b')
const $IO = $.UnaryType(
'future-io/IO',
(x) => x && x['@@type'] === 'future-io/IO',
() => []
)
const $Task = $.UnaryType(
'Task',
(x) => x && typeof x.fork === 'function',
() => []
)
const env = $.env.concat([
$IO,
$Task
])
const def = $.create({ checkTypes: true, env })