Comparing version 1.1.4 to 1.1.5
@@ -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 isNone=function isNone(value){return value===null||value===undefined};var Curry=exports.Curry=function Curry(func){for(var _len=arguments.length,args=Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){args[_key-1]=arguments[_key]}return args.length>=func.length?func.apply(undefined,args):Curry.bind.apply(Curry,[undefined,func].concat(args))};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){run(value,func);return monad};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 _len2=arguments.length,args=Array(_len2),_key2=0;_key2<_len2;_key2++){args[_key2]=arguments[_key2]}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 _len3=arguments.length,args=Array(_len3),_key3=0;_key3<_len3;_key3++){args[_key3]=arguments[_key3]}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 run=monad.run;monad.run=function(func){(valueIsNone?function(){}:run)(value,func);return monad}});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; | ||
/* 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(func){return!!(func&&func.constructor&&func.call&&func.apply)};var idFunction=function idFunction(value){return value};var isNone=function isNone(value){return value===null||value===undefined};var Curry=exports.Curry=function Curry(func){for(var _len=arguments.length,args=Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){args[_key-1]=arguments[_key]}return args.length>=func.length?func.apply(undefined,args):Curry.bind.apply(Curry,[undefined,func].concat(args))};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,idFunction);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){run(value,func);return monad};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 _len2=arguments.length,args=Array(_len2),_key2=0;_key2<_len2;_key2++){args[_key2]=arguments[_key2]}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 _len3=arguments.length,args=Array(_len3),_key3=0;_key3<_len3;_key3++){args[_key3]=arguments[_key3]}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;monad.map=valueIsNone?function(){return monad}:monad.map;var run=monad.run;monad.run=function(func){(valueIsNone?function(){}:run)(value,func);return monad}});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; |
@@ -5,9 +5,17 @@ /* jshint -W097, esversion: 6, strict: true, node: true */ | ||
const isFunction = f => !!(f && f.constructor && f.call && f.apply); | ||
const isFunction = | ||
func => | ||
!!(func && func.constructor && func.call && func.apply); | ||
const idFunction = value => value; | ||
const idFunction = | ||
value => | ||
value; | ||
const isNone = value => value === null || value === undefined; | ||
const isNone = | ||
value => | ||
value === null || value === undefined; | ||
export const Curry = (func, ...args) => args.length >= func.length ? func(...args) : Curry.bind(this, func, ...args); | ||
export const Curry = | ||
(func, ...args) => | ||
args.length >= func.length ? func(...args) : Curry.bind(this, func, ...args); | ||
@@ -22,3 +30,3 @@ export const Monad = (modifier) => { | ||
monad.of = monad.pure = (value) => { | ||
const m = run(value, (value) => value); | ||
const m = run(value, idFunction); | ||
return m && m.is_monad ? m : unit(m); | ||
@@ -66,2 +74,3 @@ }; | ||
monad.bind = valueIsNone ? () => monad : monad.bind; | ||
monad.map = valueIsNone ? () => monad : monad.map; | ||
const run = monad.run; | ||
@@ -68,0 +77,0 @@ monad.run = (func) => { (valueIsNone ? () => { } : run)(value, func); return monad; }; |
{ | ||
"name": "liftjs", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"homepage": "https://github.com/atomable/lift.js/", | ||
@@ -9,5 +9,5 @@ "description": "lift.js is a compact monad opinionated javascript library", | ||
"scripts": { | ||
"pretest": "babel src/lift.js -o test/lift.js", | ||
"test": "mocha --require babel-register --require babel-polyfill", | ||
"prepublish": "babel src/lift.js -o npm/lift-min.js --minified && copy /y src/lift.js npm/lift.js", | ||
"pretest": "node_modules/.bin/babel ./src/lift.js -o ./test/lift.js", | ||
"test": "node_modules/.bin/mocha --require babel-register --require babel-polyfill", | ||
"prepublish": "node scripts/prepublish", | ||
"coverage": "babel src/lift.js -o test/lift.js && babel test --out-dir babel && istanbul cover node_modules/mocha/bin/_mocha babel" | ||
@@ -14,0 +14,0 @@ }, |
@@ -26,2 +26,8 @@ # lift.js — Write less code. | ||
## Monad | ||
```javascript | ||
Monad(modifier) : unit | ||
``` | ||
## lift (lifting) | ||
@@ -56,3 +62,3 @@ | ||
`Just` is an implementaion of the `Identity` monad. It's called `Just` becuse a 8 character variable is just too long. | ||
`Just` is an implementaion of the `Identity` monad. It's called `Just` because an 8 character variable is just too long. | ||
@@ -184,3 +190,3 @@ **The folowing function are available on `Just`, `Maybe`, `Valid`.** | ||
const maybeWithValue = Maybe().orElse(Just(15)); | ||
// Just[5] | ||
// Just[15] | ||
``` | ||
@@ -187,0 +193,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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
14399
6
117
220
2
1