How to use the fantasy-land.alt 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 briancavalier / creed / src / Promise.js View on Github external
return this.bimap(r, f)
  }

  [fl.ap] (pf) {
    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
github sanctuary-js / sanctuary / test / internal / List.js View on Github external
Cons (f (this.head)) (Z.map (f, this.tail));
};

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

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

List.prototype[FL.alt] = List.prototype[FL.concat];

List.prototype[FL.reduce] = function(f, x) {
  return this.isNil ?
    x :
    Z.reduce (f, f (x, this.head), this.tail);
};

List.prototype[FL.traverse] = function(typeRep, f) {
  return this.isNil ?
    Z.of (typeRep, Nil) :
    Z.ap (Z.map (Cons, f (this.head)), Z.traverse (typeRep, f, this.tail));
};

List.prototype.inspect =
List.prototype['@@show'] = function() {
  return this.isNil ?
github sanctuary-js / sanctuary-type-classes / test / List.js View on Github external
Cons (f (this.head), Z.map (f, this.tail));
};

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

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

List.prototype[FL.alt] = List.prototype[FL.concat];

List.prototype[FL.reduce] = function(f, x) {
  return this.isNil ?
    x :
    Z.reduce (f, f (x, this.head), this.tail);
};

List.prototype[FL.traverse] = function(typeRep, f) {
  return this.isNil ?
    Z.of (typeRep, Nil) :
    Z.ap (Z.map (curry2 (Cons), f (this.head)),
          Z.traverse (typeRep, f, this.tail));
};

List.prototype.inspect =
List.prototype['@@show'] = function() {
github sanctuary-js / sanctuary-type-classes / test / Maybe.js View on Github external
return this.isJust && pred (this.value) ? this : Maybe.Nothing;
};

Maybe.prototype[FL.map] = function(f) {
  return this.isJust ? Maybe.Just (f (this.value)) : Maybe.Nothing;
};

Maybe.prototype[FL.ap] = function(other) {
  return other.isJust ? Z.map (other.value, this) : Maybe.Nothing;
};

Maybe.prototype[FL.chain] = function(f) {
  return this.isJust ? f (this.value) : Maybe.Nothing;
};

Maybe.prototype[FL.alt] = function(other) {
  return this.isJust ? this : other;
};

Maybe.prototype[FL.reduce] = function(f, x) {
  return this.isJust ? f (x, this.value) : x;
};

Maybe.prototype.inspect =
Maybe.prototype['@@show'] = function() {
  return this.isJust ? 'Just (' + show (this.value) + ')' : 'Nothing';
};

module.exports = Maybe;
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
}
github fantasyland / static-land / src / fromFLType.js View on Github external
const alt = (ta, tb) => ta[$.alt](tb)
const reduce = (fn, seed, tx) => tx[$.reduce](fn, seed)