Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* 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';
};
};
/*
|------------------------------------------------------------------------------
| Fantasy Land
|------------------------------------------------------------------------------
*/
// 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;
module.exports = IO;
// ap :: Writer w a ~> Apply (a -> b) -> Writer w b
Writer.prototype.ap = function ap(apply) {
return Writer.ap(apply, this);
};
/*
|------------------------------------------------------------------------------
| Fantasy Land
|------------------------------------------------------------------------------
*/
// Static Monad
Writer[fl.of] = Writer.of;
Writer[fl.chain] = Writer.chain;
Writer[fl.map] = Writer.map;
Writer[fl.ap] = Writer.ap;
// Instance Monad
Writer.prototype[fl.of] = Writer.prototype.of;
Writer.prototype[fl.chain] = Writer.prototype.chain;
Writer.prototype[fl.map] = Writer.prototype.map;
Writer.prototype[fl.ap] = Writer.prototype.ap;
module.exports = Writer;
/*
|------------------------------------------------------------------------------
| Fantasy Land
|------------------------------------------------------------------------------
*/
// Static Monad
Writer[fl.of] = Writer.of;
Writer[fl.chain] = Writer.chain;
Writer[fl.map] = Writer.map;
Writer[fl.ap] = Writer.ap;
// Instance Monad
Writer.prototype[fl.of] = Writer.prototype.of;
Writer.prototype[fl.chain] = Writer.prototype.chain;
Writer.prototype[fl.map] = Writer.prototype.map;
Writer.prototype[fl.ap] = Writer.prototype.ap;
module.exports = Writer;
/*
|------------------------------------------------------------------------------
| 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;
};
/*
|------------------------------------------------------------------------------
| 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;
module.exports = RemoteData;
// andThen :: Monad m => ReaderT e m a ~> (a -> ReaderT e m b) -> ReaderT e m b
ReaderT.prototype.andThen = ReaderT.prototype.chain;
// 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;
};
return new Monad(value);
}
static get ['@@type']() {
return 'monad-t/Monad';
}
constructor(value) {
this.value = value;
}
[fl.map](fn) {
return functorTrait[fl.map].call(this, fn);
}
[fl.chain](fn) {
return chainTrait[fl.chain].call(this, fn);
}
[fl.ap](applyWithFn) {
return applyTrait[fl.ap].call(this, applyWithFn);
}
}
aliasesForType(Monad);
module.exports = Monad;
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 :
Z.reduce (f, f (x, this.head), this.tail);
};
List.prototype[FL.traverse] = function(typeRep, f) {
return this.isNil ?
Z.of (typeRep, Nil) :
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
}