How to use fantasy-land - 10 common examples

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 / 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
github sanctuary-js / sanctuary / test / internal / List.js View on Github external
//    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 :
    Cons (this.head) (Z.concat (this.tail, other));
};
github sanctuary-js / sanctuary-type-classes / test / Maybe.js View on Github external
/* otherwise */ Maybe.Just (Z.concat (this.value, other.value));
}

Maybe.prototype[FL.filter] = function(pred) {
  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';
};
github sanctuary-js / sanctuary-type-classes / test / Sum.js View on Github external
//  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) + ')';
};

module.exports = Sum;
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 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) {