How to use the fantasy-land.of 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 / 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 dustinws / zoom / src / result.js View on Github external
};

// isOk :: Result a b ~> c -> Bool
Result.prototype.isOk = function isOk() {
  return Result.isOk(this);
};


/*
 |------------------------------------------------------------------------------
 | Fantasy Land
 |------------------------------------------------------------------------------
 */

// Result Applicative
Result[fl.of] = Result.of;

// Result Chain
Result[fl.chain] = Result.chain;
Result.prototype[fl.chain] = Result.prototype.chain;

// Result Functor
Result[fl.map] = Result.map;
Result.prototype[fl.map] = Result.prototype.map;

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


// Ok Applicative
Result.Ok[fl.of] = Result.Ok.of;
github dustinws / zoom / src / packages / data / maybe / index.js View on Github external
*   return get('location')(data)
 *     .andThen(get('address'))
 *     .andThen(get('streetNumber'));
 * }
 *
 * // You can use the `withDefault` method to extract the value
 * getStreetNumber(data).withDefault('No Address') // '42'
 *
 * getStreetNumber({}).withDefault('No Address') // 'No Address'
 *
 * @class Maybe
 * @memberof module:Zoom.Data
 */

// Maybe Applicative
Maybe[FL.of] = Maybe.of;

// Maybe Chain
Maybe[FL.chain] = Maybe.chain;
Maybe.prototype[FL.chain] = Maybe.prototype.chain;

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

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


// Just Applicative
Maybe.Just[FL.of] = Maybe.Just.of;
github dustinws / zoom / src / result.js View on Github external
// Result Functor
Result[fl.map] = Result.map;
Result.prototype[fl.map] = Result.prototype.map;

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


// Ok Applicative
Result.Ok[fl.of] = Result.Ok.of;
Result.Ok.prototype[fl.of] = Result.Ok.prototype.of;

// Err Applicative
Result.Err[fl.of] = Result.Err.of;
Result.Err.prototype[fl.of] = Result.Err.prototype.of;


module.exports = Result;
github dustinws / zoom / src / reader.js View on Github external
ReaderT.prototype[fl.map] = ReaderT.prototype.map;
  ReaderT.prototype[fl.ap] = ReaderT.prototype.ap;

  return ReaderT;
};


/*
 |------------------------------------------------------------------------------
 | Fantasy Land
 |------------------------------------------------------------------------------
 */

// Reader Applicative
Reader[fl.of] = Reader.of;
Reader.prototype[fl.of] = Reader.prototype.of;

// Reader Chain
Reader[fl.chain] = Reader.chain;
Reader.prototype[fl.chain] = Reader.prototype.chain;

// Reader Functor
Reader[fl.map] = Reader.map;
Reader.prototype[fl.map] = Reader.prototype.map;

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


module.exports = Reader;
github dustinws / zoom / src / packages / validation / index.js View on Github external
import FL from 'fantasy-land';
import Validation from './Validation';

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

// Validation Chain
Validation[FL.chain] = Validation.chain;
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;
github dustinws / zoom / src / packages / io / index.js View on Github external
import FL from 'fantasy-land';
import IO from './IO';

// IO Applicative
IO[FL.of] = IO.of;
IO.prototype[FL.of] = IO.prototype.of;

// IO Chain
IO[FL.chain] = IO.chain;
IO.prototype[FL.chain] = IO.prototype.chain;

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

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

export default IO;
github dustinws / zoom / src / validation.js View on Github external
// 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 dustinws / zoom / src / remote-data.js View on Github external
// withDefault :: RemoteData a b ~> b -> b
RemoteData.prototype.withDefault = function withDefault(defaultValue) {
  return RemoteData.withDefault(defaultValue, this);
};


/*
 |------------------------------------------------------------------------------
 | Fantasy Land
 |------------------------------------------------------------------------------
 */

// RemoteData Applicative
RemoteData[FL.of] = RemoteData.of;
RemoteData.prototype[FL.of] = RemoteData.prototype.of;

// RemoteData Chain
RemoteData[FL.chain] = RemoteData.chain;
RemoteData.prototype[FL.chain] = RemoteData.prototype.chain;

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

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

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