How to use the sanctuary-def.Either function in sanctuary-def

To help you get started, we’ve selected a few sanctuary-def examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fabioluz / fun-js / src / fun.js View on Github external
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
}
github sanctuary-js / sanctuary / test / is.js View on Github external
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);

  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);