exalted.future
Advanced tools
Comparing version 0.0.10 to 0.0.11
@@ -1,1 +0,213 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var compose=function(){for(var u=[],t=0;t<arguments.length;t++)u[t]=arguments[t];return function(){for(var t,n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return u.slice(0,u.length-1).reduceRight(function(t,n){return n(t)},(t=u.slice(u.length-1))[0].apply(t,n))}},fmap=function(n){return function(t){return t.map(n)}},map=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return function(t){return n.reduceRight(function(t,n){return fmap(n)(t)},t)}},leftIdentity={Left:function(t){return t}},rightIdentity={Right:function(t){return t}},identity={Left:function(t){return t},Right:function(t){return t}},isNull=function(t){return null==t},Right=function(n){return{ap:function(t){return t.isLeft?t:t.map(function(t){return"function"==typeof t?t(n):n})},cata:function(t){return t&&t.Right?t.Right(n):n},chain:function(t){return t(n)},equals:function(t){return t.cata({Right:function(t){return n===t},Left:function(t){return n===t}})},fold:function(){return n},inspect:function(){return"Right("+n+")"},isLeft:!1,map:function(t){return Right(t(n))},of:function(t){return Right(t)}}};Right.of=function(t){return Right(t)};var Left=function(n){return{ap:function(t){return t.isLeft?t:Left(n)},cata:function(t){return t&&t.Left?t.Left(n):n},chain:function(){return Left(n)},map:function(t){return Left(n)},equals:function(t){return t.cata({Left:function(t){return n===t},Right:function(t){return n===t}})},fold:function(){return n},inspect:function(){return"Left("+n+")"},isLeft:!0,of:function(t){return Left(t)}}};Left.of=function(t){return Left(t)};var nullable=function(t){return(isNull(t)?Left:Right)(t)},encaseEither=function(t){try{return Right(t())}catch(t){return Left(t)}},fork2=function(r){return function(t,n){return r(t,n)}},chain=function(t){return function(u){return Future(function(n,r){return fork2(t)(function(t){return n(t)},function(t){return u(t).fork(n,r)})})}},Future=function(r){return{map:function(n){return chain(r)(function(t){return Future.of(n(t))})},chain:chain(r),fork:fork2(r),cata:function(t){return void 0===t&&(t=function(t){return t}),r(t,t)}}};Future.of=function(r){return Future(function(t,n){return n(r)})},Future.fromPromise=function(r){return Future(function(t,n){return Future.fromPromise(r.then(n,t))})};var countSparse=function(t){return t.filter(function(t){return void 0!==t}).length},all=function(o){return Future(function(u,e,i){return void 0===i&&(i=!1),o.reduce(function(n,t,r){return t.fork(function(t){return!i&&(i=!0,u(t))},function(t){return n[r]=t,!i&&countSparse(n)===o.length&&e(n)}),n},[])})};Future.all=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return all([].concat.apply([],t))};var Id=function(n){return{ap:function(t){return t.map(function(t){return t(n)})},cata:function(t){return t&&t.Right?t.Right(n):n},chain:function(t){return t(n)},equals:function(t){return t.cata({Right:function(t){return n===t}})},fold:function(){return n},map:function(t){return Id(t(n))},of:function(t){return Id(t)},inspect:function(){return"Id("+n+")"}}};Id.of=function(t){return Id(t)};var isNull$1=function(t){return null==t},maybe=function(t){return isNull$1(t)?Nothing():Just(t)};maybe.of=function(t){return Maybe(t)};var Nothing=function(){return{ap:function(){return Nothing()},cata:function(t){return t&&t.Left?t.Left():void 0},chain:function(){return Nothing()},alt:function(t){return maybe(t())},equals:function(t){return t.cata({Right:function(t){return null==t}})},fold:function(){},inspect:function(){return"Nothing()"},map:function(){return Nothing()},of:function(t){return maybe(t)}}},Just=function(n){return{ap:function(t){return t.map(function(t){return t(n)})},cata:function(t){return t&&t.Right?t.Right(n):n},chain:function(t){return t(n)},alt:function(t){return Just(n)},equals:function(t){return t.cata({Right:function(t){return n===t}})},fold:function(){return n},inspect:function(){return"Just("+n+")"},map:function(t){return maybe(t(n))},of:function(t){return maybe(t)}}};Just.of=function(t){return Just(t)};var Maybe=maybe,encase=function(t){try{return Maybe(t())}catch(t){return Nothing()}},head=function(t){return 0<t.length?Maybe(t[0]):Nothing()},tail=function(t){return 0<t.length?Maybe(t.slice(1)):Nothing()},last=function(t){return 0<t.length?Maybe(t[t.length-1]):Nothing()},get=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return function(t){return n.reduce(function(t,n){return t.map(function(t){return t&&t[n]})},Maybe(t))}};exports.Future=Future,exports.Id=Id,exports.Just=Just,exports.Left=Left,exports.Maybe=Maybe,exports.Nothing=Nothing,exports.Right=Right,exports.compose=compose,exports.encase=encase,exports.encaseEither=encaseEither,exports.get=get,exports.head=head,exports.identity=identity,exports.last=last,exports.leftIdentity=leftIdentity,exports.map=map,exports.maybe=maybe,exports.nullable=nullable,exports.rightIdentity=rightIdentity,exports.tail=tail; | ||
const compose = (...rest) => (...a) => | ||
rest | ||
.slice(0, rest.length - 1) | ||
.reduceRight((acc, func) => func(acc), rest.slice(rest.length - 1)[0](...a)) | ||
const fmap = f => functor => functor.map(f) | ||
const map = (...functions) => functor => functions.reduceRight((acc, f) => fmap(f)(acc), functor) | ||
const id = a => a | ||
const leftIdentity = { Left: id } | ||
const rightIdentity = { Right: id } | ||
const identity = { Left: id, Right: id } | ||
const isNull = value => value === null || value === undefined | ||
const identity$1 = a => a | ||
const Right = a => ({ | ||
ap: app => (app.isLeft ? app : app.map((b = identity$1) => b(a))), | ||
bimap: (left = identity$1, right = identity$1) => right(a), | ||
cata: (f = { Right: identity$1 }) => f.Right(a), | ||
chain: (f = identity$1) => f(a), | ||
equals: r => r.cata({ Right: b => a === b, Left: b => a === b }), | ||
fold: (f = identity$1) => f(a), | ||
foldl: (f = identity$1) => f(null), | ||
foldr: (f = identity$1) => f(a), | ||
inspect: () => `Right(${a})`, | ||
isLeft: false, | ||
map: (f = identity$1) => Right(f(a)), | ||
of: a => Right(a), | ||
swap: () => Left(a) | ||
}) | ||
Right.of = a => Right(a) | ||
const Left = a => ({ | ||
ap: app => (app.isLeft ? app : Left(a)), | ||
bimap: (left = identity$1, right = identity$1) => left(a), | ||
cata: (f = { Left: identity$1 }) => f.Left(a), | ||
chain: () => Left(a), | ||
map: () => Left(a), | ||
equals: l => l.cata({ Left: b => a === b, Right: b => a === b }), | ||
fold: (f = identity$1) => f(a), | ||
foldl: (f = identity$1) => f(a), | ||
foldr: (f = identity$1) => f(null), | ||
inspect: () => `Left(${a})`, | ||
isLeft: true, | ||
of: a => Left(a), | ||
swap: () => Right(a) | ||
}) | ||
Left.of = a => Left(a) | ||
const nullable = x => (isNull(x) ? Left(x) : Right(x)) | ||
const Either = (l, r) => [Left(l), Right(r)] | ||
const encase = (f = identity$1) => { | ||
try { | ||
return Right(f(null)) | ||
} catch (err) { | ||
return Left(err) | ||
} | ||
} | ||
Either.encase = encase | ||
Right.encase = encase | ||
Left.encase = encase | ||
const fork2 = action => (error, success) => action(error, success) | ||
const chain = action => func => | ||
Future((reject, resolve) => | ||
fork2(action)(e => reject(e), data => func(data).fork(reject, resolve))) | ||
const Future = action => ({ | ||
map: func => chain(action)(x => Future.of(func(x))), | ||
chain: chain(action), | ||
fork: fork2(action), | ||
cata: f => action(f, f) | ||
}) | ||
Future.of = x => Future((reject, resolve) => resolve(x)) | ||
Future.fromPromise = promise => | ||
Future((reject, resolve) => Future.fromPromise(promise.then(resolve, reject))) | ||
const countSparse = arr => arr.filter(x => x !== undefined).length | ||
const all = futures => | ||
Future((left, right, errored = false) => | ||
futures.reduce( | ||
(results, future, i) => ( | ||
future.fork( | ||
error => !errored && ((errored = true), left(error)), | ||
result => ( | ||
(results[i] = result), | ||
!errored && countSparse(results) === futures.length && right(results))), | ||
results | ||
), | ||
[] | ||
)) | ||
Future.all = (...futures) => all([].concat(...futures)) | ||
const identity$2 = a => a | ||
const Id = a => ({ | ||
ap: app => app.map((f = identity$2) => f(a)), | ||
bimap: (left = identity$2, right = identity$2) => right(a), | ||
cata: (f = { Right: identity$2 }) => f.Right(a), | ||
chain: (f = identity$2) => f(a), | ||
equals: id => id.cata({ Right: b => a === b }), | ||
fold: (f = identity$2) => f(a), | ||
foldl: (f = identity$2) => f(null), | ||
foldr: (f = identity$2) => f(a), | ||
map: f => Id(f(a)), | ||
of: a => Id(a), | ||
inspect: () => `Id(${a})` | ||
}) | ||
Id.of = a => Id(a) | ||
const isNull$1 = value => value === null || value === undefined | ||
const Maybe = a => (isNull$1(a) ? Nothing() : Just(a)) | ||
Maybe.of = a => Maybe(a) | ||
const identity$3 = a => a | ||
const Nothing = () => ({ | ||
ap: () => Nothing(), | ||
bimap: (left = identity$3, right = identity$3) => left(null), | ||
cata: (f = { Left: identity$3 }) => f.Left(null), | ||
chain: () => Nothing(), | ||
alt: (f = identity$3) => Maybe(f(null)), | ||
equals: id => id.cata({ Right: b => isNull$1(b) }), | ||
fold: () => {}, | ||
foldl: () => {}, | ||
foldr: () => {}, | ||
inspect: () => 'Nothing()', | ||
map: () => Nothing(), | ||
of: a => Maybe(a) | ||
}) | ||
Nothing.of = () => Nothing() | ||
const Just = a => ({ | ||
ap: app => app.map(f => f(a)), | ||
bimap: (left = identity$3, right = identity$3) => right(a), | ||
cata: (f = { Right: identity$3 }) => f.Right(a), | ||
chain: (f = identity$3) => f(a), | ||
alt: () => Just(a), | ||
equals: id => id.cata({ Right: b => a === b }), | ||
fold: (f = identity$3) => f(a), | ||
foldl: () => {}, | ||
foldr: (f = identity$3) => f(a), | ||
inspect: () => `Just(${a})`, | ||
map: (f = identity$3) => Maybe(f(a)), | ||
of: a => Maybe(a) | ||
}) | ||
Just.of = a => Just(a) | ||
const encase$1 = (f = identity$3) => { | ||
try { | ||
return Maybe(f(null)) | ||
} catch (_) { | ||
return Nothing() | ||
} | ||
} | ||
Just.encase = encase$1 | ||
Nothing.encase = encase$1 | ||
Maybe.encase = encase$1 | ||
const head = list => (list.length > 0 ? Maybe(list[0]) : Nothing()) | ||
const tail = list => (list.length > 0 ? Maybe(list.slice(1)) : Nothing()) | ||
const last = list => (list.length > 0 ? Maybe(list[list.length - 1]) : Nothing()) | ||
const get = (...args) => a => args.reduce((acc, b) => acc.map(c => c && c[b]), Maybe(a)) | ||
export { | ||
Either, | ||
Future, | ||
Id, | ||
Just, | ||
Left, | ||
Maybe, | ||
Nothing, | ||
Right, | ||
compose, | ||
get, | ||
head, | ||
identity, | ||
last, | ||
leftIdentity, | ||
map, | ||
nullable, | ||
rightIdentity, | ||
tail | ||
} |
{ | ||
"name": "exalted.future", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "Exalted monadic library & functional fun, fantasy-land compliant, mostly.", | ||
@@ -8,24 +8,26 @@ "repository": "https://github.com/pre63/exalted.future.git", | ||
"license": "Apache-2.0", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.esm.js", | ||
"browser": "dist/index.umd.js", | ||
"type": "module", | ||
"private": false, | ||
"sideEffects": false, | ||
"scripts": { | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"build:tsd": "rm -rf dist && tsc src/index.ts --emitDeclarationOnly -d --outDir dist", | ||
"rollup": "./node_modules/.bin/rollup -c", | ||
"build": "yarn build:tsd && yarn rollup", | ||
"deploy": "yarn build && yarn publish" | ||
"build": "yarn rollup", | ||
"deploy": "yarn build && yarn publish", | ||
"test": "node --experimental-vm-modules ./node_modules/.bin/jest --coverage" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^24.0.18", | ||
"jest": "^24.9.0", | ||
"rollup": "^1.23.1", | ||
"rollup-plugin-sizes": "^1.0.3", | ||
"rollup-plugin-typescript2": "^0.24.3", | ||
"rollup-plugin-uglify": "^6.0.4", | ||
"ts-jest": "^24.1.0", | ||
"typescript": "^3.6.3" | ||
"@babel/preset-env": "^7.12.1", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
"@rollup/plugin-commonjs": "^16.0.0", | ||
"@rollup/plugin-node-resolve": "^10.0.0", | ||
"jest": "^26.6.1", | ||
"rollup": "^2.32.1", | ||
"rollup-plugin-sizes": "^1.0.3" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [ | ||
@@ -32,0 +34,0 @@ "fp", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
79099
7
2087
Yes
9
1