How to use the fantasy-land.zero function in fantasy-land

To help you get started, we’ve selected a few fantasy-land 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 sanctuary-js / sanctuary / test / internal / List.js View on Github external
const Nil = List.Nil = new _List ('Nil');

//    Cons :: a -> List a -> List a
const Cons = List.Cons = function Cons(head) {
  eq (arguments.length) (Cons.length);
  return function Cons$1(tail) {
    eq (arguments.length) (Cons$1.length);
    return new _List ('Cons', head, tail);
  };
};

List[FL.empty] = () => Nil;

List[FL.of] = x => Cons (x) (Nil);

List[FL.zero] = List[FL.empty];

List.prototype[FL.equals] = function(other) {
  return this.isNil ?
    other.isNil :
    other.isCons &&
      Z.equals (other.head, this.head) &&
      Z.equals (other.tail, this.tail);
};

List.prototype[FL.concat] = function(other) {
  return this.isNil ?
    other :
    Cons (this.head) (Z.concat (this.tail, other));
};

List.prototype[FL.filter] = function(pred) {
github sanctuary-js / sanctuary-type-classes / test / Maybe.js View on Github external
if (this.isNothing || Z.Semigroup.test (this.value)) {
    this[FL.concat] = Maybe$prototype$concat;
  }
}

Maybe['@@type'] = 'sanctuary-type-classes/Maybe';

Maybe.Nothing = new _Maybe ('Nothing');

Maybe.Just = function(x) { return new _Maybe ('Just', x); };

Maybe[FL.empty] = function() { return Maybe.Nothing; };

Maybe[FL.of] = Maybe.Just;

Maybe[FL.zero] = Maybe[FL.empty];

function Maybe$prototype$equals(other) {
  return this.isNothing ? other.isNothing
                        : other.isJust && Z.equals (this.value, other.value);
}

function Maybe$prototype$lte(other) {
  return this.isNothing || other.isJust && Z.lte (this.value, other.value);
}

function Maybe$prototype$concat(other) {
  return this.isNothing ? other :
         other.isNothing ? this :
         /* otherwise */ Maybe.Just (Z.concat (this.value, other.value));
}
github sanctuary-js / sanctuary-type-classes / test / List.js View on Github external
}

//  Nil :: List a
var Nil = List.Nil = new _List ('Nil');

//  Cons :: (a, List a) -> List a
var Cons = List.Cons = function Cons(head, tail) {
  eq (arguments.length, Cons.length);
  return new _List ('Cons', head, tail);
};

List[FL.empty] = function() { return Nil; };

List[FL.of] = function(x) { return Cons (x, Nil); };

List[FL.zero] = List[FL.empty];

List.prototype['@@type'] = 'sanctuary-type-classes/List@1';

List.prototype[FL.equals] = function(other) {
  return this.isNil ?
    other.isNil :
    other.isCons &&
      Z.equals (other.head, this.head) &&
      Z.equals (other.tail, this.tail);
};

List.prototype[FL.concat] = function(other) {
  return this.isNil ?
    other :
    Cons (this.head, Z.concat (this.tail, other));
};
github briancavalier / creed / src / Promise.js View on Github external
return pf.ap(this)
  }

  [fl.chain] (f) {
    return this.chain(f)
  }

  [fl.concat] (p) {
    return this.concat(p)
  }

  [fl.alt] (p) {
    return this.or(p)
  }

  static [fl.zero] () {
    return never()
  }

  // @deprecated The name concat is deprecated, use or() instead.
  concat (b) {
    return this.or(b)
  }
}

// data Promise e a where
//   Future    :: Promise e a
//   Fulfilled :: a -> Promise e a
//   Rejected  :: Error e => e -> Promise e a
//   Never     :: Promise e a

// Future :: Promise e a
github fantasyland / static-land / src / fromFLType.js View on Github external
function defAvailableMethods(Constructor) {
  const result = []
  if (Constructor[$.of]) result.push('of')
  if (Constructor[$.empty]) result.push('empty')
  if (Constructor[$.chainRec]) result.push('chainRec')
  if (Constructor[$.zero]) result.push('zero')
  if (Constructor.prototype[$.equals]) result.push('equals')
  if (Constructor.prototype[$.map]) result.push('map')
  if (Constructor.prototype[$.bimap]) result.push('bimap')
  if (Constructor.prototype[$.promap]) result.push('promap')
  if (Constructor.prototype[$.concat]) result.push('concat')
  if (Constructor.prototype[$.ap]) result.push('ap')
  if (Constructor.prototype[$.alt]) result.push('alt')
  if (Constructor.prototype[$.reduce]) result.push('reduce')
  if (Constructor.prototype[$.traverse]) result.push('traverse')
  if (Constructor.prototype[$.chain]) result.push('chain')
  if (Constructor.prototype[$.extend]) result.push('extend')
  if (Constructor.prototype[$.extract]) result.push('extract')
  return result
}