Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 ($.Boolean) (true)) (true);
eq (S.is ($.Boolean) (false)) (true);
eq (S.is ($.Boolean) (new Boolean (true))) (false);
eq (S.is ($.Boolean) (new Boolean (false))) (false);
eq (S.is ($.Array ($.Integer)) (null)) (false);
eq (S.is ($.Array ($.Integer)) (undefined)) (false);
eq (S.is ($.Array ($.Integer)) (['1', '2', '3'])) (false);
eq (S.is ($.Array ($.Integer)) ([1, 2, 3.14])) (false);
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);