Comparing version 1.0.5 to 1.1.0
@@ -1,1 +0,1 @@ | ||
/* jshint -W097, esversion: 6, strict: true, node: true *//* global module */'use strict';Object.defineProperty(exports,'__esModule',{value:true});function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}var isFunction=function isFunction(f){return!!(f&&f.constructor&&f.call&&f.apply)};var idFunction=function idFunction(value){return value};var isSome=function isSome(value){return!isNone(value)};var isNone=function isNone(value){return value===null||value===undefined};var Monad=exports.Monad=function Monad(modifier){var prototype=Object.create({is_monad:true});var unit=function unit(value){var run=function run(value,func,args){return isFunction(func)?func.apply(undefined,[value].concat(_toConsumableArray(args||[]))):monad};prototype.bind=function(func,args){return run(value,func,args)};var monad=Object.create(prototype);monad.of=monad.pure=function(value){var m=run(value,function(value){return value});return m&&m.is_monad?m:unit(m)};monad.get=function(){return value};monad.chain=monad.flatMap=monad.bind;monad.map=function(func){return unit(func(value))};monad.join=function(){return monad.bind(idFunction)};monad.toMaybe=function(){return Maybe(value)};monad.run=function(func){return run(value,func)};if(isFunction(modifier)){modifier(monad,value)}return monad};var apply=function apply(prototype,name,func,unit){prototype[name]=func;return unit};unit.lift=function(name,func){return apply(prototype,name,function(){for(var _len=arguments.length,args=Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}var m=prototype.bind(func,args);return m&&m.is_monad?m:unit(m)},unit)};unit.lift_value=function(name,func){return apply(prototype,name,function(){for(var _len2=arguments.length,args=Array(_len2),_key2=0;_key2<_len2;_key2++){args[_key2]=arguments[_key2]}return prototype.bind(func,args)},unit)};unit.method=function(name,func){return apply(prototype,name,func,unit)};return unit};var Just=exports.Just=Monad();var Maybe=exports.Maybe=Monad(function(monad,value){var valueIsNone=isNone(value);monad.none=monad.nothing=function(){return Maybe()};monad.isNone=monad.isNothing=function(){return valueIsNone};monad.isSome=monad.isJust=function(){return!valueIsNone};monad.orSome=monad.orJust=function(orValue){return valueIsNone?orValue:value};monad.orElse=function(orMonad){return valueIsNone?orMonad:monad};monad.bind=valueIsNone?function(){return monad}:monad.bind});var validFunctions=function validFunctions(monad,value){monad.success=monad.s=function(value){return Success(value)};monad.fail=monad.f=function(value){return Fail(value)};monad.of=function(value){return Success(value)};monad.isSuccess=function(){return monad.isSuccessValue};monad.isFail=function(){return!monad.isSuccessValue};monad.ap=function(validationWithFn){return monad.isSuccess()?validationWithFn.map(function(fn){return fn(value)}):validationWithFn.isFail()?monad.fail([].concat(value,validationWithFn.fail())):monad}};var Success=Monad(function(monad,value){monad.isSuccessValue=true;validFunctions(monad,value)});var Fail=Monad(function(monad,value){monad.isSuccessValue=false;validFunctions(monad,value)});var Valid=exports.Valid=Monad(function(monad,value){validFunctions(monad,value)}); | ||
/* jshint -W097, esversion: 6, strict: true, node: true *//* global module */'use strict';Object.defineProperty(exports,'__esModule',{value:true});function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}var isFunction=function isFunction(f){return!!(f&&f.constructor&&f.call&&f.apply)};var idFunction=function idFunction(value){return value};var isSome=function isSome(value){return!isNone(value)};var isNone=function isNone(value){return value===null||value===undefined};var Monad=exports.Monad=function Monad(modifier){var prototype=Object.create({is_monad:true});var unit=function unit(value){var run=function run(value,func,args){return isFunction(func)?func.apply(undefined,[value].concat(_toConsumableArray(args||[]))):monad};prototype.bind=function(func,args){return run(value,func,args)};var monad=Object.create(prototype);monad.of=monad.pure=function(value){var m=run(value,function(value){return value});return m&&m.is_monad?m:unit(m)};monad.get=function(){return value};monad.chain=monad.flatMap=monad.bind;monad.map=function(func){return unit(func(value))};monad.join=function(){return monad.bind(idFunction)};monad.toMaybe=function(){return Maybe(value)};monad.run=function(func){return run(value,func)};if(isFunction(modifier)){modifier(monad,value)}return monad};var apply=function apply(prototype,name,func,unit){prototype[name]=func;return unit};unit.lift=function(name,func){return apply(prototype,name,function(){for(var _len=arguments.length,args=Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}var m=prototype.bind(func,args);return m&&m.is_monad?m:unit(m)},unit)};unit.lift_value=function(name,func){return apply(prototype,name,function(){for(var _len2=arguments.length,args=Array(_len2),_key2=0;_key2<_len2;_key2++){args[_key2]=arguments[_key2]}return prototype.bind(func,args)},unit)};unit.method=function(name,func){return apply(prototype,name,func,unit)};return unit};var Just=exports.Just=Monad();var Maybe=exports.Maybe=Monad(function(monad,value){var valueIsNone=isNone(value);monad.none=monad.nothing=function(){return Maybe()};monad.isNone=monad.isNothing=function(){return valueIsNone};monad.isSome=monad.isJust=function(){return!valueIsNone};monad.orSome=monad.orJust=function(orValue){return valueIsNone?orValue:value};monad.orElse=function(orMonad){return valueIsNone?orMonad:monad};monad.bind=valueIsNone?function(){return monad}:monad.bind});var successFactory=function successFactory(value){return Success(value)};var failFactory=function failFactory(value){return Fail(value)};var validFunctions=function validFunctions(monad,value){monad.success=monad.s=successFactory;monad.fail=monad.f=failFactory;monad.isSuccess=function(){return monad.isSuccessValue};monad.isFail=function(){return!monad.isSuccessValue};monad.ap=function(validationWithFn){return monad.isSuccess()?validationWithFn.map(function(fn){return fn(value)}):validationWithFn.isFail()?monad.fail([].concat(value,validationWithFn.fail())):monad}};var Success=Monad(function(monad,value){monad.isSuccessValue=true;validFunctions(monad,value)});var Fail=Monad(function(monad,value){monad.isSuccessValue=false;validFunctions(monad,value)});var Valid=exports.Valid=Monad(function(monad,value){validFunctions(monad,value)});Valid.success=Valid.s=successFactory;Valid.fail=Valid.f=failFactory; |
11
lift.js
@@ -65,6 +65,8 @@ /* jshint -W097, esversion: 6, strict: true, node: true */ | ||
const successFactory = (value) => Success(value); | ||
const failFactory = (value) => Fail(value); | ||
const validFunctions = (monad, value) => { | ||
monad.success = monad.s = (value) => Success(value); | ||
monad.fail = monad.f = (value) => Fail(value); | ||
monad.of = (value) => Success(value); | ||
monad.success = monad.s = successFactory; | ||
monad.fail = monad.f = failFactory; | ||
monad.isSuccess = () => monad.isSuccessValue; | ||
@@ -95,1 +97,4 @@ monad.isFail = () => !monad.isSuccessValue; | ||
Valid.success = Valid.s = successFactory; | ||
Valid.fail = Valid.f = failFactory; | ||
{ | ||
"name": "liftjs", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/atomable/lift.js/", | ||
@@ -5,0 +5,0 @@ "description": "lift.js is a compact monad opinionated javascript library", |
@@ -123,12 +123,12 @@ /* jshint -W097, esversion: 6, strict: true, node: true */ | ||
var successFactory = function successFactory(value) { | ||
return Success(value); | ||
}; | ||
var failFactory = function failFactory(value) { | ||
return Fail(value); | ||
}; | ||
var validFunctions = function validFunctions(monad, value) { | ||
monad.success = monad.s = function (value) { | ||
return Success(value); | ||
}; | ||
monad.fail = monad.f = function (value) { | ||
return Fail(value); | ||
}; | ||
monad.of = function (value) { | ||
return Success(value); | ||
}; | ||
monad.success = monad.s = successFactory; | ||
monad.fail = monad.f = failFactory; | ||
monad.isSuccess = function () { | ||
@@ -160,1 +160,4 @@ return monad.isSuccessValue; | ||
}); | ||
Valid.success = Valid.s = successFactory; | ||
Valid.fail = Valid.f = failFactory; |
@@ -9,3 +9,3 @@ /* jshint -W097, esversion: 6, strict: true, node: true */ | ||
describe('A Validation', () => { | ||
const successString = Valid().success("abcd"); | ||
const successString = Valid.success("abcd"); | ||
const successMap = (val) => "success " + val; | ||
@@ -28,6 +28,6 @@ | ||
it('will be transformed by a bind', () => { | ||
should(successString.bind((val) => Valid().success("efgh")) | ||
should(successString.bind((val) => Valid.success("efgh")) | ||
.get()).equal("efgh"); | ||
should(successString.bind((val) => Valid().fail("big fail"))) | ||
should(successString.bind((val) => Valid.fail("big fail"))) | ||
.containEql(Valid().f("big fail")); | ||
@@ -38,3 +38,3 @@ | ||
should(successString.flatMap((val) => Valid().fail("big fail"))) | ||
should(successString.flatMap((val) => Valid.fail("big fail"))) | ||
.containEql(Valid().f("big fail")); | ||
@@ -44,3 +44,3 @@ }); | ||
const failString = Valid().fail("error dude"); | ||
const failString = Valid.fail("error dude"); | ||
const failMap = (val) => "fail: " + val; | ||
@@ -54,6 +54,6 @@ | ||
it('will not be transformed by a bind', () => { | ||
should(failString.bind((val) => Valid().fail("big fail"))) | ||
should(failString.bind((val) => Valid.fail("big fail"))) | ||
.containEql(Valid().f("error dude")); | ||
should(failString.flatMap((val) => Valid().fail("big fail"))) | ||
should(failString.flatMap((val) => Valid.fail("big fail"))) | ||
.containEql(Valid().f("error dude")); | ||
@@ -60,0 +60,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26100
466