From 892708992d9169563f1927a9edfd16c91f7d8425 Mon Sep 17 00:00:00 2001 From: saltylight Date: Thu, 21 Mar 2019 11:14:54 +0900 Subject: [PATCH 1/2] :sparkles: added mapT, mapTT to d.ts, js --- src/monet.d.ts | 2 ++ src/monet.js | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/monet.d.ts b/src/monet.d.ts index e3de405..170c9c8 100644 --- a/src/monet.d.ts +++ b/src/monet.d.ts @@ -54,6 +54,8 @@ interface IMonad extends Functor, Bind, Applicative { chain(fn: (val: T) => IMonad): IMonad; map(fn: (val: T) => V): IMonad; join(): IMonad; // only if T = IMonad + mapT(fn: (val: V1) => V2): IMonad>; // only if T = IMonad + mapTT(fn: (val: V1) => V2): IMonad>>; // only if T = IMonad> /* These are monet-Monad-specific: */ takeLeft(m: IMonad): IMonad; diff --git a/src/monet.js b/src/monet.js index 178f1cb..2c12840 100644 --- a/src/monet.js +++ b/src/monet.js @@ -77,7 +77,7 @@ var targetType = target[TYPE_KEY] || target.constructor && target.constructor[TYPE_KEY] - return Boolean(targetType) && + return Boolean(targetType) && targetType.length >= typeName.length && targetType.indexOf(typeName) === targetType.length - typeName.length } @@ -714,7 +714,7 @@ }) }, toArray: function () { - return this.map(function (val) { + return this.map(function (val) { return [val] }).orLazy(function () { return [] @@ -1376,6 +1376,13 @@ }) } } + + type.prototype.mapT = function(fn) { + return this.map(monad => monad.map(fn)); + } + type.prototype.mapTT = function(fn) { + return this.map(monad => monad.mapT(fn)); + } } function addFunctorOps(type) { From 741d7426997cdb4402f210e0f784731933c4214c Mon Sep 17 00:00:00 2001 From: saltylight Date: Thu, 21 Mar 2019 14:20:29 +0900 Subject: [PATCH 2/2] :shirt: fix lint error --- src/monet.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/monet.js b/src/monet.js index 2c12840..24a8d74 100644 --- a/src/monet.js +++ b/src/monet.js @@ -1378,10 +1378,14 @@ } type.prototype.mapT = function(fn) { - return this.map(monad => monad.map(fn)); + return this.map(function (ma) { + return ma.map(fn) + }) } type.prototype.mapTT = function(fn) { - return this.map(monad => monad.mapT(fn)); + return this.map(function (ma) { + return ma.mapT(fn) + }) } }