How to use the fantasy-land.empty 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
(x => type (x) === List['@@type'])
  (list => list);

//    Nil :: List a
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 :
github sanctuary-js / sanctuary / test / internal / Sum.js View on Github external
//    Sum :: Number -> Sum
function Sum(value) {
  if (!(this instanceof Sum)) return new Sum (value);
  this.value = value;
}

Sum['@@type'] = 'sanctuary/Sum';

//    Type :: Type
Sum.Type = $.NullaryType
  (Sum['@@type'])
  ('')
  ([])
  (x => type (x) === Sum['@@type']);

Sum[FL.empty] = () => Sum (0);

Sum.prototype[FL.equals] = function(other) {
  return Z.equals (this.value, other.value);
};

Sum.prototype[FL.concat] = function(other) {
  return Sum (this.value + other.value);
};

Sum.prototype[FL.invert] = function() {
  return Sum (-this.value);
};

Sum.prototype.inspect =
Sum.prototype['@@show'] = function() {
  return 'Sum (' + show (this.value) + ')';
github dustinws / zoom / src / validation.js View on Github external
// Validation Functor
Validation[fl.map] = Validation.map;
Validation.prototype[fl.map] = Validation.prototype.map;

// Validation Apply
Validation[fl.ap] = Validation.ap;
Validation.prototype[fl.ap] = Validation.prototype.ap;

// Validation Semigroup
Validation[fl.concat] = Validation.concat;
Validation.prototype[fl.concat] = Validation.prototype.concat;

// Validation Monoid
Validation[fl.empty] = Validation.empty;
Validation.prototype[fl.empty] = Validation.prototype.empty;


// Success Applicative
Validation.Success[fl.of] = Validation.Success.of;
Validation.Success.prototype[fl.of] = Validation.Success.prototype.of;

// Failure Applicative
Validation.Failure[fl.of] = Validation.Failure.of;
Validation.Failure.prototype[fl.of] = Validation.Failure.prototype.of;


module.exports = Validation;
github jongold / further / src / index.js View on Github external
Style.of = Style.prototype.of;
Style.prototype[fl.of] = Style.prototype.of;
Style[fl.of] = Style.of;

// #concat :: Semigroup Style => Style ~> Style -> Style
Style.prototype.concat = function(a) {
  return new Style(props => {
    return { ...this.resolve(props), ...a.resolve(props) };
  });
};
Style.prototype[fl.concat] = Style.prototype.concat;

// .empty :: Monoid Style => () -> Style
Style.prototype.empty = () => Style.of({});
Style.empty = Style.prototype.empty;
Style.prototype[fl.empty] = Style.prototype.empty;
Style[fl.empty] = Style.empty;

// #map :: Functor Style => Style a ~> (a -> b) -> Style b
Style.prototype.map = function(f) {
  return new Style(props => {
    return f(this.resolve(props));
  });
};
Style.prototype[fl.map] = Style.prototype.map;

// chain :: Chain Style => Style a ~> (a -> Style b) -> Style b
Style.prototype.chain = function(f) {
  return new Style(props => {
    const a = this.resolve(props);

    return f(a).resolve(props);
github dustinws / zoom / src / packages / validation / index.js View on Github external
Validation.prototype[FL.chain] = Validation.prototype.chain;

// Validation Functor
Validation[FL.map] = Validation.map;
Validation.prototype[FL.map] = Validation.prototype.map;

// Validation Apply
Validation[FL.ap] = Validation.ap;
Validation.prototype[FL.ap] = Validation.prototype.ap;

// Validation Semigroup
Validation[FL.concat] = Validation.concat;
Validation.prototype[FL.concat] = Validation.prototype.concat;

// Validation Monoid
Validation[FL.empty] = Validation.empty;


// Success Applicative
Validation.Success[FL.of] = Validation.Success.of;
Validation.Success.prototype[FL.of] = Validation.Success.prototype.of;

// Success Chain
Validation.Success[FL.chain] = Validation.Success.chain;
Validation.Success.prototype[FL.chain] = Validation.Success.prototype.chain;

// Success Functor
Validation.Success[FL.map] = Validation.Success.map;
Validation.Success.prototype[FL.map] = Validation.Success.prototype.map;

// Success Apply
Validation.Success[FL.ap] = Validation.Success.ap;
github jongold / further / src / __tests__ / index.js View on Github external
it("is fantasy-land compatible", () => {
    const st = Style[fl.empty]();
    expect(st.of({}) instanceof Style).toBe(true);
  });
  it("implements Semigroup right identity", () => {
github rpominov / fun-task / src / index.js View on Github external
function makeFLCompatible(constructor: any) {
  constructor.prototype[fl.of] = constructor[fl.of] = constructor.of
  constructor.prototype[fl.empty] = constructor[fl.empty] = constructor.empty
  constructor.prototype[fl.chainRec] = constructor[fl.chainRec] = constructor.chainRec
  constructor.prototype[fl.concat] = constructor.prototype.concat
  constructor.prototype[fl.map] = constructor.prototype.map
  constructor.prototype[fl.bimap] = constructor.prototype.bimap
  constructor.prototype[fl.ap] = constructor.prototype.ap
  constructor.prototype[fl.chain] = constructor.prototype.chain
}
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
}