How to use the fantasy-land.equals 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
//    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) {
  return this.isNil ?
    Nil :
github sanctuary-js / sanctuary-type-classes / test / Sum.js View on Github external
var show = require ('sanctuary-show');

var Z = require ('..');


//  Sum :: Number -> Sum
function Sum(value) {
  if (!(this instanceof Sum)) return new Sum (value);
  this.value = value;
}

Sum[FL.empty] = function() { return Sum (0); };

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

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 sanctuary-js / sanctuary / test / internal / Compose.js View on Github external
return function ComposeF(G) {
    function ComposeFG(value) {
      if (!(this instanceof ComposeFG)) return new ComposeFG (value);
      this.value = value;
    }

    ComposeFG['@@type'] = 'sanctuary/Compose';

    ComposeFG[FL.of] = function(x) {
      return ComposeFG (of (F) (of (G) (x)));
    };

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

    ComposeFG.prototype[FL.map] = function(f) {
      return ComposeFG (map (map (f)) (this.value));
    };

    ComposeFG.prototype[FL.ap] = function(other) {
      return ComposeFG (ap (map (ap) (other.value)) (this.value));
    };

    //  name :: TypeRep a -> String
    function name(typeRep) {
      return typeof typeRep['@@type'] === 'string' ?
               typeRep['@@type'].replace (/^[^/]*[/]/, '') :
               typeRep.name;
github sanctuary-js / sanctuary-type-classes / test / Identity.js View on Github external
var show = require ('sanctuary-show');

var Z = require ('..');


//  Identity :: a -> Identity a
function Identity(value) {
  if (!(this instanceof Identity)) return new Identity (value);
  this.value = value;
}

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

Identity[FL.of] = Identity;

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

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

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

Identity.prototype[FL.map] = function(f) {
  return Identity (f (this.value));
};

Identity.prototype[FL.ap] = function(other) {
github sanctuary-js / sanctuary / test / internal / Sum.js View on Github external
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 fantasyland / fantasy-laws / src / internal / Compose.js View on Github external
module.exports = curry2 (function(F, G) {
  function Compose(value) {
    if (!(this instanceof Compose)) return new Compose (value);
    this.value = value;
  }

  Compose['@@type'] = 'fantasy-laws/Compose';

  Compose[FL.of] = function(x) {
    return Compose (of (F) (of (G) (x)));
  };

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

  Compose.prototype[FL.map] = function(f) {
    return Compose (map (map (f)) (this.value));
  };

  Compose.prototype[FL.ap] = function(other) {
    return Compose (ap (map (ap) (other.value)) (this.value));
  };

  //  name :: TypeRep a -> String
  function name(typeRep) {
    return typeof typeRep['@@type'] === 'string' ?
             typeRep['@@type'].replace (/^[^/]*[/]/, '') :
             typeRep.name;
github dustinws / zoom / src / packages / tuple / index.js View on Github external
import FL from 'fantasy-land';
import Tuple from './Tuple';

// Tuple Applicative
Tuple[FL.equals] = Tuple.equals;
Tuple.prototype[FL.equals] = Tuple.prototype.equals;

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


export default Tuple;
github Risto-Stevcev / lazy-either / test / either.js View on Github external
it('should return true if a and b are equal (reflexivity) (1)', function(done) {
    LazyEither.Right('good')[FL.equals](LazyEither.Right('good'), res => {
      expect(res).to.be.true
      done()
    })
  })
github sanctuary-js / sanctuary-type-classes / test / Maybe.js View on Github external
function _Maybe(tag, value) {
  this.isNothing = tag === 'Nothing';
  this.isJust = tag === 'Just';
  if (this.isJust) this.value = value;

  if (this.isNothing || Z.Setoid.test (this.value)) {
    this[FL.equals] = Maybe$prototype$equals;
  }

  if (this.isNothing || Z.Ord.test (this.value)) {
    this[FL.lte] = Maybe$prototype$lte;
  }

  if (this.isNothing || Z.Semigroup.test (this.value)) {
    this[FL.concat] = Maybe$prototype$concat;
  }
}
github char0n / ramda-adjunct / src / internal / fantasy-land / Identity.js View on Github external
this.value = value;
  }

  get() {
    return this.value;
  }

  [fl.ap](...args) {
    return applyTrait[fl.ap].call(this, ...args);
  }

  [fl.map](...args) {
    return functorTrait[fl.map].call(this, ...args);
  }

  [fl.equals](...args) {
    return setoidTrait[fl.equals].call(this, ...args);
  }

  [fl.concat](...args) {
    return semigroupTrait[fl.concat].call(this, ...args);
  }
}

aliases(Identity).forEach(([alias, fn]) => {
  Identity[alias] = fn;
});
aliases(Identity.prototype).forEach(([alias, fn]) => {
  Identity.prototype[alias] = fn;
});

export default Identity;