How to use the fantasy-land.ap 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 dustinws / zoom / src / reader.js View on Github external
// map :: Monad m => ReaderT e m a ~> (a -> b) -> ReaderT e m b
  ReaderT.prototype.map = function map(callback) {
    return ReaderT.map(callback, this);
  };

  // ap :: Monad m => ReaderT e m a ~> Apply (a -> b) -> ReaderT e m b
  ReaderT.prototype.ap = function ap(apply) {
    return ReaderT.ap(apply, this);
  };

  // Static Monad
  ReaderT[fl.of] = ReaderT.of;
  ReaderT[fl.chain] = ReaderT.chain;
  ReaderT[fl.map] = ReaderT.map;
  ReaderT[fl.ap] = ReaderT.ap;

  // Instance Monad
  ReaderT.prototype[fl.of] = ReaderT.prototype.of;
  ReaderT.prototype[fl.chain] = ReaderT.prototype.chain;
  ReaderT.prototype[fl.map] = ReaderT.prototype.map;
  ReaderT.prototype[fl.ap] = ReaderT.prototype.ap;

  return ReaderT;
};
github dustinws / zoom / src / result.js View on Github external
|------------------------------------------------------------------------------
 */

// 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;
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 / task.js View on Github external
|------------------------------------------------------------------------------
 | Fantasy Land
 |------------------------------------------------------------------------------
 */

// Static Monad
Task[fl.of] = Task.of;
Task[fl.chain] = Task.chain;
Task[fl.map] = Task.map;
Task[fl.ap] = Task.ap;

// Instance Monad
Task.prototype[fl.of] = Task.prototype.of;
Task.prototype[fl.chain] = Task.prototype.chain;
Task.prototype[fl.map] = Task.prototype.map;
Task.prototype[fl.ap] = Task.prototype.ap;


module.exports = Task;
github dustinws / zoom / src / packages / io / index.js View on Github external
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 / result.js View on Github external
*/

// 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;
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 / packages / data / maybe / index.js View on Github external
* @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;
Maybe.Just.prototype[FL.of] = Maybe.Just.prototype.of;

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

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

// Maybe.Just Apply
github dustinws / zoom / src / packages / validation / index.js View on Github external
// Failure Applicative
Validation.Failure[FL.of] = Validation.Failure.of;
Validation.Failure.prototype[FL.of] = Validation.Failure.prototype.of;

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

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

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

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


export default Validation;
github Risto-Stevcev / lazy-either / test / either.js View on Github external
it('should propagate a Left value (1)', function(done) {
    LazyEither.Right(2)[FL.ap](LazyEither.Left('bad')).value(res => {
      expect(res).to.deep.equal(S.Left('bad'))
      done()
    })
  })
github sanctuary-js / sanctuary-type-classes / test / List.js View on Github external
List.prototype[FL.filter] = function(pred) {
  return this.isNil ?
    Nil :
    pred (this.head) ?
      Cons (this.head, Z.filter (pred, this.tail)) :
      Z.filter (pred, this.tail);
};

List.prototype[FL.map] = function(f) {
  return this.isNil ?
    Nil :
    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 :
github fantasyland / static-land / src / fromFLType.js View on Github external
function fromSL(T) {
  function Adapter(slValue) {
    this._slValue = slValue
  }
  Adapter[$.of] = x => new Adapter(T.of(x))
  Adapter.prototype[$.of] = Adapter[$.of]
  Adapter.prototype[$.map] = function(f) { return new Adapter(T.map(f, this.unwrap())) }
  Adapter.prototype[$.ap] = function(f) { return new Adapter(T.ap(f.unwrap(), this.unwrap())) }
  Adapter.prototype.unwrap = function() { return this._slValue }
  return Adapter
}