Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

exalted.future

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exalted.future - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

dist/compose.js

203

dist/index.js

@@ -5,182 +5,29 @@ 'use strict';

var compose = function () {
var rest = [];
for (var _i = 0; _i < arguments.length; _i++) {
rest[_i] = arguments[_i];
}
return function () {
var _a;
var a = [];
for (var _i = 0; _i < arguments.length; _i++) {
a[_i] = arguments[_i];
}
return rest
.slice(0, rest.length - 1)
.reduceRight(function (acc, func) { return func(acc); }, (_a = rest.slice(rest.length - 1))[0].apply(_a, a));
};
};
var fmap = function (f) { return function (functor) { return functor.map(f); }; };
var map = function () {
var functions = [];
for (var _i = 0; _i < arguments.length; _i++) {
functions[_i] = arguments[_i];
}
return function (functor) { return functions.reduceRight(function (acc, f) { return fmap(f)(acc); }, functor); };
};
var leftIdentity = { Left: function (a) { return a; } };
var rightIdentity = { Right: function (a) { return a; } };
var identity = { Left: function (a) { return a; }, Right: function (a) { return a; } };
var compose = require('./compose.js');
var either = require('./either.js');
var future = require('./future.js');
var identity = require('./identity.js');
var maybe = require('./maybe.js');
var isNull = function (value) { return value === null || value === undefined; };
var Right = function (a) { return ({
ap: function (app) { return app.isLeft ? app : app.map(function (b) { return typeof b === 'function' ? b(a) : a; }); },
cata: function (f) { return (f && f.Right) ? f.Right(a) : a; },
chain: function (f) { return f(a); },
equals: function (r) { return r.cata({ Right: function (b) { return a === b; }, Left: function (b) { return a === b; } }); },
fold: function () { return a; },
inspect: function () { return "Right(" + a + ")"; },
isLeft: false,
map: function (f) { return Right(f(a)); },
of: function (a) { return Right(a); }
}); };
Right.of = function (a) { return Right(a); };
var Left = function (a) { return ({
ap: function (app) { return app.isLeft ? app : Left(a); },
cata: function (f) { return (f && f.Left) ? f.Left(a) : a; },
chain: function () { return Left(a); },
map: function (_) { return Left(a); },
equals: function (l) { return l.cata({ Left: function (b) { return a === b; }, Right: function (b) { return a === b; } }); },
fold: function () { return a; },
inspect: function () { return "Left(" + a + ")"; },
isLeft: true,
of: function (a) { return Left(a); }
}); };
Left.of = function (a) { return Left(a); };
var nullable = function (x) { return isNull(x) ? Left(x) : Right(x); };
var encaseEither = function (f) {
try {
return Right(f());
}
catch (err) {
return Left(err);
}
};
var fork2 = function (action) { return function (error, success) { return action(error, success); }; };
var chain = function (action) { return function (func) {
return Future(function (reject, resolve) {
return fork2(action)(function (e) { return reject(e); }, function (data) { return func(data).fork(reject, resolve); });
});
}; };
var Future = function (action) { return ({
map: function (func) { return chain(action)(function (x) { return Future.of(func(x)); }); },
chain: chain(action),
fork: fork2(action),
cata: function (f) {
if (f === void 0) { f = function (a) { return a; }; }
return action(f, f);
}
}); };
Future.of = function (x) { return Future(function (reject, resolve) { return resolve(x); }); };
Future.fromPromise = function (promise) {
return Future(function (reject, resolve) { return Future.fromPromise(promise.then(resolve, reject)); });
};
var countSparse = function (arr) { return arr.filter(function (x) { return x !== undefined; }).length; };
var all = function (futures) {
return Future(function (left, right, errored) {
if (errored === void 0) { errored = false; }
return futures.reduce(function (results, future, i) {
return (future.fork(function (error) { return !errored && ((errored = true), left(error)); }, function (result) {
return ((results[i] = result), !errored &&
countSparse(results) === futures.length &&
right(results));
}), results);
}, []);
});
};
Future.all = function () {
var futures = [];
for (var _i = 0; _i < arguments.length; _i++) {
futures[_i] = arguments[_i];
}
return all([].concat.apply([], futures));
};
var Id = function (a) { return ({
ap: function (app) { return app.map(function (f) { return f(a); }); },
cata: function (f) { return f && f.Right ? f.Right(a) : a; },
chain: function (f) { return f(a); },
equals: function (id) { return id.cata({ Right: function (b) { return a === b; } }); },
fold: function () { return a; },
map: function (f) { return Id(f(a)); },
of: function (a) { return Id(a); },
inspect: function () { return "Id(" + a + ")"; }
}); };
Id.of = function (a) { return Id(a); };
var isNull$1 = function (value) { return value === null || value === undefined; };
var maybe = function (a) { return isNull$1(a) ? Nothing() : Just(a); };
maybe.of = function (a) { return Maybe(a); };
var Nothing = function () { return ({
ap: function () { return Nothing(); },
cata: function (f) { return (f && f.Left) ? f.Left() : undefined; },
chain: function () { return Nothing(); },
alt: function (f) { return maybe(f()); },
equals: function (n) { return n.cata({ Right: function (b) { return b == undefined; } }); },
fold: function () { return undefined; },
inspect: function () { return 'Nothing()'; },
map: function () { return Nothing(); },
of: function (a) { return maybe(a); }
}); };
var Just = function (a) { return ({
ap: function (app) { return app.map(function (f) { return f(a); }); },
cata: function (f) { return (f && f.Right) ? f.Right(a) : a; },
chain: function (f) { return f(a); },
alt: function (f) { return Just(a); },
equals: function (id) { return id.cata({ Right: function (b) { return a === b; } }); },
fold: function () { return a; },
inspect: function () { return "Just(" + a + ")"; },
map: function (f) { return maybe(f(a)); },
of: function (a) { return maybe(a); }
}); };
Just.of = function (a) { return Just(a); };
var Maybe = maybe;
var encase = function (f) {
try {
return Maybe(f());
}
catch (_a) {
return Nothing();
}
};
var head = function (list) { return list.length > 0 ? Maybe(list[0]) : Nothing(); };
var tail = function (list) { return list.length > 0 ? Maybe(list.slice(1)) : Nothing(); };
var last = function (list) { return list.length > 0 ? Maybe(list[list.length - 1]) : Nothing(); };
var get = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return function (a) { return args.reduce(function (acc, b) { return acc.map(function (c) { return c && c[b]; }); }, Maybe(a)); };
};
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;
exports.compose = compose.compose;
exports.identity = compose.identity;
exports.leftIdentity = compose.leftIdentity;
exports.map = compose.map;
exports.rightIdentity = compose.rightIdentity;
exports.Left = either.Left;
exports.Right = either.Right;
exports.encaseEither = either.encaseEither;
exports.nullable = either.nullable;
exports.Future = future.Future;
exports.Id = identity.Id;
exports.Just = maybe.Just;
exports.Maybe = maybe.Maybe;
exports.Nothing = maybe.Nothing;
exports.encase = maybe.encase;
exports.get = maybe.get;
exports.head = maybe.head;
exports.last = maybe.last;
exports.maybe = maybe.maybe;
exports.tail = maybe.tail;
{
"name": "exalted.future",
"version": "0.0.8",
"version": "0.0.9",
"description": "Exalted monadic library & functional fun, fantasy-land compliant, mostly.",

@@ -5,0 +5,0 @@ "repository": "https://github.com/pre63/exalted.future.git",

import typescript from 'rollup-plugin-typescript2'
export default {
input: 'src/index.ts',
input: ['src/index.ts', 'src/compose.ts', 'src/either.ts', 'src/future.ts', 'src/identity.ts', 'src/maybe.ts'],
output: {
name: 'exalted.future',
format: 'cjs',
file: 'dist/index.js'
dir:'dist/'
},

@@ -10,0 +10,0 @@ plugins: [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc