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

purify-ts

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

purify-ts - npm Package Compare versions

Comparing version 0.16.0-beta.2 to 0.16.0-beta.3

22

Codec.js

@@ -45,2 +45,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.intersect = exports.date = exports.tuple = exports.nonEmptyList = exports.maybe = exports.lazy = exports.exactly = exports.record = exports.array = exports.oneOf = exports.enumeration = exports.unknown = exports.boolean = exports.nullable = exports.optional = exports.nullType = exports.number = exports.string = exports.Codec = void 0;
var Either_1 = require("./Either");

@@ -302,9 +303,16 @@ var Function_1 = require("./Function");

var e_4, _a;
var _loop_1 = function (codec) {
var res = Either_1.Either.encase(function () { return codec.encode(input); })
.mapLeft(function (_) { return ''; })
.chain(codec.decode);
if (res.isRight()) {
return { value: codec.encode(input) };
}
};
try {
for (var codecs_2 = __values(codecs), codecs_2_1 = codecs_2.next(); !codecs_2_1.done; codecs_2_1 = codecs_2.next()) {
var codec = codecs_2_1.value;
var res = codec.decode(input);
if (res.isRight()) {
return codec.encode(input);
}
var state_1 = _loop_1(codec);
if (typeof state_1 === "object")
return state_1.value;
}

@@ -321,3 +329,3 @@ }

},
schema: function () { return ({ oneOf: codecs.map(function (x) { return x.schema(); }).filter(Boolean) }); }
schema: function () { return ({ oneOf: codecs.map(function (x) { return x.schema(); }) }); }
});

@@ -500,3 +508,3 @@ };

type: 'array',
items: codecs.map(function (x) { return x.schema(); }).filter(Boolean),
items: codecs.map(function (x) { return x.schema(); }),
additionalItems: false,

@@ -548,4 +556,4 @@ minItems: codecs.length,

},
schema: function () { return ({ allOf: [t, u].map(function (x) { return x.schema(); }).filter(Boolean) }); }
schema: function () { return ({ allOf: [t, u].map(function (x) { return x.schema(); }) }); }
});
};

@@ -9,4 +9,2 @@ import { Maybe } from './Maybe';

export interface Either<L, R> {
/** Internal property and subject to breaking changes, please use some of the available methods on the object if you want to access it */
__value: L | R;
/** Returns true if `this` is `Left`, otherwise it returns false */

@@ -89,2 +87,4 @@ isLeft(): this is Either<L, never>;

encase<L extends Error, R>(throwsF: () => R): Either<L, R>;
/** Turns a list of `Either`s into an `Either` of list */
sequence<L, R>(eithers: Either<L, R>[]): Either<L, R[]>;
'fantasy-land/of'<L, R>(value: R): Either<L, R>;

@@ -91,0 +91,0 @@ }

@@ -14,2 +14,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Right = exports.Left = exports.Either = void 0;
var Maybe_1 = require("./Maybe");

@@ -68,2 +69,23 @@ exports.Either = {

},
sequence: function (eithers) {
var e_3, _a;
var res = [];
try {
for (var eithers_1 = __values(eithers), eithers_1_1 = eithers_1.next(); !eithers_1_1.done; eithers_1_1 = eithers_1.next()) {
var e = eithers_1_1.value;
if (e.isLeft()) {
return e;
}
res.push(e.extract());
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (eithers_1_1 && !eithers_1_1.done && (_a = eithers_1.return)) _a.call(eithers_1);
}
finally { if (e_3) throw e_3.error; }
}
return right(res);
},
'fantasy-land/of': function (value) {

@@ -74,5 +96,5 @@ return exports.Either.of(value);

var Right = /** @class */ (function () {
function Right(value) {
function Right(__value) {
this.__value = __value;
this._ = 'R';
this.__value = value;
}

@@ -104,6 +126,6 @@ Right.prototype.isLeft = function () {

Right.prototype.ap = function (other) {
return other.isLeft() ? other : this.map(other.__value);
return other.isRight() ? this.map(other.extract()) : other;
};
Right.prototype.equals = function (other) {
return other.isRight() ? this.__value === other.__value : false;
return other.isRight() ? this.__value === other.extract() : false;
};

@@ -195,5 +217,5 @@ Right.prototype.chain = function (f) {

var Left = /** @class */ (function () {
function Left(value) {
function Left(__value) {
this.__value = __value;
this._ = 'L';
this.__value = value;
}

@@ -228,3 +250,3 @@ Left.prototype.isLeft = function () {

Left.prototype.equals = function (other) {
return other.isLeft() ? other.__value === this.__value : false;
return other.isLeft() ? other.extract() === this.__value : false;
};

@@ -231,0 +253,0 @@ Left.prototype.chain = function (_) {

import { Either } from './Either';
import { MaybeAsync } from './MaybeAsync';
export interface EitherAsync<L, R> {
export interface EitherAsyncTypeRef {
/** Constructs an EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */
<L, R>(runPromise: (helpers: EitherAsyncHelpers<L>) => PromiseLike<R>): EitherAsync<L, R>;
/** Constructs an EitherAsync object from a function that returns an Either wrapped in a Promise */
fromPromise<L, R>(f: () => PromiseLike<Either<L, R>>): EitherAsync<L, R>;
/** Constructs an EitherAsync object from a function that returns a Promise. The left type is defaulted to the built-in Error type */
liftPromise<R, L = Error>(f: () => PromiseLike<R>): EitherAsync<L, R>;
/** Constructs an EitherAsync object from an Either */
liftEither<L, R>(either: Either<L, R>): EitherAsync<L, R>;
}
export interface EitherAsync<L, R> extends PromiseLike<Either<L, R>> {
/**

@@ -23,5 +33,5 @@ * It's important to remember how `run` will behave because in an

/** Transforms `this` with a function that returns a `EitherAsync`. Behaviour is the same as the regular Either#chain */
chain<R2>(f: (value: R) => EitherAsync<L, R2>): EitherAsync<L, R2>;
chain<R2>(f: (value: R) => PromiseLike<Either<L, R2>>): EitherAsync<L, R2>;
/** The same as EitherAsync#chain but executes the transformation function only if the value is Left. Useful for recovering from errors */
chainLeft<L2>(f: (value: L) => EitherAsync<L2, R>): EitherAsync<L2, R>;
chainLeft<L2>(f: (value: L) => PromiseLike<Either<L2, R>>): EitherAsync<L2, R>;
/** Converts `this` to a MaybeAsync, discarding any error values */

@@ -32,3 +42,5 @@ toMaybeAsync(): MaybeAsync<R>;

'fantasy-land/map'<R2>(f: (value: R) => R2): EitherAsync<L, R2>;
'fantasy-land/chain'<R2>(f: (value: R) => EitherAsync<L, R2>): EitherAsync<L, R2>;
'fantasy-land/chain'<R2>(f: (value: R) => PromiseLike<Either<L, R2>>): EitherAsync<L, R2>;
/** WARNING: This is implemented only for Promise compatibility. Please use `chain` instead. */
then: any;
}

@@ -45,9 +57,2 @@ export interface EitherAsyncValue<R> extends PromiseLike<R> {

}
/** Constructs an EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */
export declare const EitherAsync: <L, R>(runPromise: (helpers: EitherAsyncHelpers<L>) => PromiseLike<R>) => EitherAsync<L, R>;
/** Constructs an EitherAsync object from a function that returns an Either wrapped in a Promise */
export declare const fromPromise: <L, R>(f: () => Promise<Either<L, R>>) => EitherAsync<L, R>;
/** Constructs an EitherAsync object from a function that returns a Promise. The left type is defaulted to the built-in Error type */
export declare const liftPromise: <R, L = Error>(f: () => Promise<R>) => EitherAsync<L, R>;
/** Constructs an EitherAsync object from an Either */
export declare const liftEither: <L, R>(either: Either<L, R>) => EitherAsync<L, R>;
export declare const EitherAsync: EitherAsyncTypeRef;

@@ -39,2 +39,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.EitherAsync = void 0;
var Either_1 = require("./Either");

@@ -44,6 +45,6 @@ var MaybeAsync_1 = require("./MaybeAsync");

liftEither: function (either) {
if (either.isLeft()) {
throw either.__value;
if (either.isRight()) {
return Promise.resolve(either.extract());
}
return Promise.resolve(either.__value);
throw either.extract();
},

@@ -60,2 +61,3 @@ fromPromise: function (promise) {

this.runPromise = runPromise;
this[Symbol.toStringTag] = 'EitherAsync';
}

@@ -111,3 +113,3 @@ EitherAsyncImpl.prototype.run = function () {

value = _a.sent();
return [2 /*return*/, helpers.fromPromise(f(value).run())];
return [2 /*return*/, helpers.fromPromise(f(value))];
}

@@ -129,3 +131,3 @@ });

e_3 = _a.sent();
return [2 /*return*/, helpers.fromPromise(f(e_3).run())];
return [2 /*return*/, helpers.fromPromise(f(e_3))];
case 3: return [2 /*return*/];

@@ -175,19 +177,21 @@ }

};
EitherAsyncImpl.prototype.then = function (onfulfilled, onrejected) {
return this.run().then(onfulfilled, onrejected);
};
return EitherAsyncImpl;
}());
/** Constructs an EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */
exports.EitherAsync = function (runPromise) { return new EitherAsyncImpl(runPromise); };
/** Constructs an EitherAsync object from a function that returns an Either wrapped in a Promise */
exports.fromPromise = function (f) { return exports.EitherAsync(function (_a) {
var fP = _a.fromPromise;
return fP(f());
}); };
/** Constructs an EitherAsync object from a function that returns a Promise. The left type is defaulted to the built-in Error type */
exports.liftPromise = function (f) { return exports.EitherAsync(f); };
/** Constructs an EitherAsync object from an Either */
exports.liftEither = function (either) {
return exports.EitherAsync(function (_a) {
var liftEither = _a.liftEither;
return liftEither(either);
});
};
exports.EitherAsync = Object.assign(function (runPromise) { return new EitherAsyncImpl(runPromise); }, {
fromPromise: function (f) { return exports.EitherAsync(function (_a) {
var fP = _a.fromPromise;
return fP(f());
}); },
liftPromise: function (f) {
return exports.EitherAsync(f);
},
liftEither: function (either) {
return exports.EitherAsync(function (_a) {
var liftEither = _a.liftEither;
return liftEither(either);
});
}
});
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.intersect = exports.date = exports.tuple = exports.nonEmptyList = exports.maybe = exports.lazy = exports.exactly = exports.record = exports.array = exports.oneOf = exports.enumeration = exports.unknown = exports.boolean = exports.nullable = exports.optional = exports.nullType = exports.number = exports.string = exports.Codec = void 0;
const Either_1 = require("./Either");

@@ -207,3 +208,5 @@ const Function_1 = require("./Function");

for (const codec of codecs) {
const res = codec.decode(input);
const res = Either_1.Either.encase(() => codec.encode(input))
.mapLeft((_) => '')
.chain(codec.decode);
if (res.isRight()) {

@@ -215,3 +218,3 @@ return codec.encode(input);

},
schema: () => ({ oneOf: codecs.map((x) => x.schema()).filter(Boolean) })
schema: () => ({ oneOf: codecs.map((x) => x.schema()) })
});

@@ -364,3 +367,3 @@ /** A codec for an array */

type: 'array',
items: codecs.map((x) => x.schema()).filter(Boolean),
items: codecs.map((x) => x.schema()),
additionalItems: false,

@@ -406,3 +409,3 @@ minItems: codecs.length,

},
schema: () => ({ allOf: [t, u].map((x) => x.schema()).filter(Boolean) })
schema: () => ({ allOf: [t, u].map((x) => x.schema()) })
});

@@ -9,4 +9,2 @@ import { Maybe } from './Maybe';

export interface Either<L, R> {
/** Internal property and subject to breaking changes, please use some of the available methods on the object if you want to access it */
__value: L | R;
/** Returns true if `this` is `Left`, otherwise it returns false */

@@ -89,2 +87,4 @@ isLeft(): this is Either<L, never>;

encase<L extends Error, R>(throwsF: () => R): Either<L, R>;
/** Turns a list of `Either`s into an `Either` of list */
sequence<L, R>(eithers: Either<L, R>[]): Either<L, R[]>;
'fantasy-land/of'<L, R>(value: R): Either<L, R>;

@@ -91,0 +91,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Right = exports.Left = exports.Either = void 0;
const Maybe_1 = require("./Maybe");

@@ -34,2 +35,12 @@ exports.Either = {

},
sequence(eithers) {
let res = [];
for (const e of eithers) {
if (e.isLeft()) {
return e;
}
res.push(e.extract());
}
return right(res);
},
'fantasy-land/of'(value) {

@@ -40,5 +51,5 @@ return exports.Either.of(value);

class Right {
constructor(value) {
constructor(__value) {
this.__value = __value;
this._ = 'R';
this.__value = value;
}

@@ -70,6 +81,6 @@ isLeft() {

ap(other) {
return other.isLeft() ? other : this.map(other.__value);
return other.isRight() ? this.map(other.extract()) : other;
}
equals(other) {
return other.isRight() ? this.__value === other.__value : false;
return other.isRight() ? this.__value === other.extract() : false;
}

@@ -160,5 +171,5 @@ chain(f) {

class Left {
constructor(value) {
constructor(__value) {
this.__value = __value;
this._ = 'L';
this.__value = value;
}

@@ -193,3 +204,3 @@ isLeft() {

equals(other) {
return other.isLeft() ? other.__value === this.__value : false;
return other.isLeft() ? other.extract() === this.__value : false;
}

@@ -196,0 +207,0 @@ chain(_) {

import { Either } from './Either';
import { MaybeAsync } from './MaybeAsync';
export interface EitherAsync<L, R> {
export interface EitherAsyncTypeRef {
/** Constructs an EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */
<L, R>(runPromise: (helpers: EitherAsyncHelpers<L>) => PromiseLike<R>): EitherAsync<L, R>;
/** Constructs an EitherAsync object from a function that returns an Either wrapped in a Promise */
fromPromise<L, R>(f: () => PromiseLike<Either<L, R>>): EitherAsync<L, R>;
/** Constructs an EitherAsync object from a function that returns a Promise. The left type is defaulted to the built-in Error type */
liftPromise<R, L = Error>(f: () => PromiseLike<R>): EitherAsync<L, R>;
/** Constructs an EitherAsync object from an Either */
liftEither<L, R>(either: Either<L, R>): EitherAsync<L, R>;
}
export interface EitherAsync<L, R> extends PromiseLike<Either<L, R>> {
/**

@@ -23,5 +33,5 @@ * It's important to remember how `run` will behave because in an

/** Transforms `this` with a function that returns a `EitherAsync`. Behaviour is the same as the regular Either#chain */
chain<R2>(f: (value: R) => EitherAsync<L, R2>): EitherAsync<L, R2>;
chain<R2>(f: (value: R) => PromiseLike<Either<L, R2>>): EitherAsync<L, R2>;
/** The same as EitherAsync#chain but executes the transformation function only if the value is Left. Useful for recovering from errors */
chainLeft<L2>(f: (value: L) => EitherAsync<L2, R>): EitherAsync<L2, R>;
chainLeft<L2>(f: (value: L) => PromiseLike<Either<L2, R>>): EitherAsync<L2, R>;
/** Converts `this` to a MaybeAsync, discarding any error values */

@@ -32,3 +42,5 @@ toMaybeAsync(): MaybeAsync<R>;

'fantasy-land/map'<R2>(f: (value: R) => R2): EitherAsync<L, R2>;
'fantasy-land/chain'<R2>(f: (value: R) => EitherAsync<L, R2>): EitherAsync<L, R2>;
'fantasy-land/chain'<R2>(f: (value: R) => PromiseLike<Either<L, R2>>): EitherAsync<L, R2>;
/** WARNING: This is implemented only for Promise compatibility. Please use `chain` instead. */
then: any;
}

@@ -45,9 +57,2 @@ export interface EitherAsyncValue<R> extends PromiseLike<R> {

}
/** Constructs an EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */
export declare const EitherAsync: <L, R>(runPromise: (helpers: EitherAsyncHelpers<L>) => PromiseLike<R>) => EitherAsync<L, R>;
/** Constructs an EitherAsync object from a function that returns an Either wrapped in a Promise */
export declare const fromPromise: <L, R>(f: () => Promise<Either<L, R>>) => EitherAsync<L, R>;
/** Constructs an EitherAsync object from a function that returns a Promise. The left type is defaulted to the built-in Error type */
export declare const liftPromise: <R, L = Error>(f: () => Promise<R>) => EitherAsync<L, R>;
/** Constructs an EitherAsync object from an Either */
export declare const liftEither: <L, R>(either: Either<L, R>) => EitherAsync<L, R>;
export declare const EitherAsync: EitherAsyncTypeRef;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EitherAsync = void 0;
const Either_1 = require("./Either");

@@ -7,6 +8,6 @@ const MaybeAsync_1 = require("./MaybeAsync");

liftEither(either) {
if (either.isLeft()) {
throw either.__value;
if (either.isRight()) {
return Promise.resolve(either.extract());
}
return Promise.resolve(either.__value);
throw either.extract();
},

@@ -23,2 +24,3 @@ fromPromise(promise) {

this.runPromise = runPromise;
this[Symbol.toStringTag] = 'EitherAsync';
}

@@ -49,3 +51,3 @@ async run() {

const value = await this.runPromise(helpers);
return helpers.fromPromise(f(value).run());
return helpers.fromPromise(f(value));
});

@@ -59,3 +61,3 @@ }

catch (e) {
return helpers.fromPromise(f(e).run());
return helpers.fromPromise(f(e));
}

@@ -84,10 +86,10 @@ });

}
then(onfulfilled, onrejected) {
return this.run().then(onfulfilled, onrejected);
}
}
/** Constructs an EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */
exports.EitherAsync = (runPromise) => new EitherAsyncImpl(runPromise);
/** Constructs an EitherAsync object from a function that returns an Either wrapped in a Promise */
exports.fromPromise = (f) => exports.EitherAsync(({ fromPromise: fP }) => fP(f()));
/** Constructs an EitherAsync object from a function that returns a Promise. The left type is defaulted to the built-in Error type */
exports.liftPromise = (f) => exports.EitherAsync(f);
/** Constructs an EitherAsync object from an Either */
exports.liftEither = (either) => exports.EitherAsync(({ liftEither }) => liftEither(either));
exports.EitherAsync = Object.assign((runPromise) => new EitherAsyncImpl(runPromise), {
fromPromise: (f) => exports.EitherAsync(({ fromPromise: fP }) => fP(f())),
liftPromise: (f) => exports.EitherAsync(f),
liftEither: (either) => exports.EitherAsync(({ liftEither }) => liftEither(either))
});
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.orderToNumber = exports.compare = exports.Order = exports.always = exports.identity = void 0;
/** The identity function, returns the value it was given */

@@ -4,0 +5,0 @@ exports.identity = (x) => x;

"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./Codec"));
__export(require("./Either"));
__export(require("./Function"));
__export(require("./List"));
__export(require("./Maybe"));
__exportStar(require("./Codec"), exports);
__exportStar(require("./Either"), exports);
__exportStar(require("./Function"), exports);
__exportStar(require("./List"), exports);
__exportStar(require("./Maybe"), exports);
var MaybeAsync_1 = require("./MaybeAsync");
exports.MaybeAsync = MaybeAsync_1.MaybeAsync;
Object.defineProperty(exports, "MaybeAsync", { enumerable: true, get: function () { return MaybeAsync_1.MaybeAsync; } });
var EitherAsync_1 = require("./EitherAsync");
exports.EitherAsync = EitherAsync_1.EitherAsync;
__export(require("./NonEmptyList"));
__export(require("./Tuple"));
Object.defineProperty(exports, "EitherAsync", { enumerable: true, get: function () { return EitherAsync_1.EitherAsync; } });
__exportStar(require("./NonEmptyList"), exports);
__exportStar(require("./Tuple"), exports);
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.List = void 0;
const Tuple_1 = require("./Tuple");

@@ -4,0 +5,0 @@ const Maybe_1 = require("./Maybe");

@@ -13,4 +13,2 @@ import { Either } from './Either';

export interface Maybe<T> {
/** Internal property and subject to breaking changes, please use some of the available methods on the object if you want to access it */
__value: T;
/** Returns true if `this` is `Just`, otherwise it returns false */

@@ -101,3 +99,3 @@ isJust(): this is AlwaysJust;

declare class Nothing implements Maybe<never> {
__value: never;
private __value;
isJust(): boolean;

@@ -104,0 +102,0 @@ isNothing(): boolean;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Nothing = exports.Just = exports.Maybe = void 0;
const Either_1 = require("./Either");

@@ -37,3 +38,9 @@ exports.Maybe = {

catMaybes(list) {
return list.filter((x) => x.isJust()).map((x) => x.__value);
let res = [];
for (const e of list) {
if (e.isJust()) {
res.push(e.extract());
}
}
return res;
},

@@ -59,4 +66,4 @@ encase(thunk) {

class Just {
constructor(value) {
this.__value = value;
constructor(__value) {
this.__value = __value;
}

@@ -79,3 +86,3 @@ isJust() {

equals(other) {
return this.__value === other.__value;
return this.extract() === other.extract();
}

@@ -86,3 +93,3 @@ map(f) {

ap(maybeF) {
return maybeF.isNothing() ? nothing : this.map(maybeF.__value);
return maybeF.isJust() ? this.map(maybeF.extract()) : nothing;
}

@@ -186,3 +193,3 @@ alt(_) {

equals(other) {
return this.__value === other.__value;
return this.extract() === other.extract();
}

@@ -189,0 +196,0 @@ map(_) {

import { Maybe } from './Maybe';
import { EitherAsync } from './EitherAsync';
export interface MaybeAsync<T> {
export interface MaybeAsyncTypeRef {
/** Constructs a MaybeAsync object from a function that takes an object full of helpers that let you lift things into the MaybeAsync context and returns a Promise */
<T>(runPromise: (helpers: MaybeAsyncHelpers) => PromiseLike<T>): MaybeAsync<T>;
/** Constructs an MaybeAsync object from a function that returns a Maybe wrapped in a Promise */
fromPromise<T>(f: () => Promise<Maybe<T>>): MaybeAsync<T>;
/** Constructs an MaybeAsync object from a function that returns a Promise */
liftPromise<T>(f: () => Promise<T>): MaybeAsync<T>;
/** Constructs an MaybeAsync object from a Maybe */
liftMaybe<T>(maybe: Maybe<T>): MaybeAsync<T>;
}
export interface MaybeAsync<T> extends PromiseLike<Maybe<T>> {
/**

@@ -21,7 +31,9 @@ * It's important to remember how `run` will behave because in an

/** Transforms `this` with a function that returns a `MaybeAsync`. Behaviour is the same as the regular Maybe#chain */
chain<U>(f: (value: T) => MaybeAsync<U>): MaybeAsync<U>;
chain<U>(f: (value: T) => PromiseLike<Maybe<U>>): MaybeAsync<U>;
/** Converts `this` to a EitherAsync with a default error value */
toEitherAsync<L>(error: L): EitherAsync<L, T>;
'fantasy-land/map'<U>(f: (value: T) => U): MaybeAsync<U>;
'fantasy-land/chain'<U>(f: (value: T) => MaybeAsync<U>): MaybeAsync<U>;
'fantasy-land/chain'<U>(f: (value: T) => PromiseLike<Maybe<U>>): MaybeAsync<U>;
/** WARNING: This is implemented only for Promise compatibility. Please use `chain` instead. */
then: any;
}

@@ -36,9 +48,2 @@ export interface MaybeAsyncValue<T> extends PromiseLike<T> {

}
/** Constructs a MaybeAsync object from a function that takes an object full of helpers that let you lift things into the MaybeAsync context and returns a Promise */
export declare const MaybeAsync: <T>(runPromise: (helpers: MaybeAsyncHelpers) => PromiseLike<T>) => MaybeAsync<T>;
/** Constructs an MaybeAsync object from a function that returns a Maybe wrapped in a Promise */
export declare const fromPromise: <T>(f: () => Promise<Maybe<T>>) => MaybeAsync<T>;
/** Constructs an MaybeAsync object from a function that returns a Promise */
export declare const liftPromise: <T>(f: () => Promise<T>) => MaybeAsync<T>;
/** Constructs an MaybeAsync object from a Maybe */
export declare const liftMaybe: <T>(maybe: Maybe<T>) => MaybeAsync<T>;
export declare const MaybeAsync: MaybeAsyncTypeRef;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MaybeAsync = void 0;
const Maybe_1 = require("./Maybe");

@@ -7,6 +8,6 @@ const EitherAsync_1 = require("./EitherAsync");

liftMaybe(maybe) {
if (maybe.isNothing()) {
throw Maybe_1.Nothing;
if (maybe.isJust()) {
return Promise.resolve(maybe.extract());
}
return Promise.resolve(maybe.__value);
throw Maybe_1.Nothing;
},

@@ -20,2 +21,3 @@ fromPromise(promise) {

this.runPromise = runPromise;
this[Symbol.toStringTag] = 'MaybeAsync';
}

@@ -36,3 +38,3 @@ async run() {

const value = await this.runPromise(helpers);
return await helpers.fromPromise(f(value).run());
return helpers.fromPromise(f(value));
});

@@ -52,10 +54,10 @@ }

}
then(onfulfilled, onrejected) {
return this.run().then(onfulfilled, onrejected);
}
}
/** Constructs a MaybeAsync object from a function that takes an object full of helpers that let you lift things into the MaybeAsync context and returns a Promise */
exports.MaybeAsync = (runPromise) => new MaybeAsyncImpl(runPromise);
/** Constructs an MaybeAsync object from a function that returns a Maybe wrapped in a Promise */
exports.fromPromise = (f) => exports.MaybeAsync(({ fromPromise: fP }) => fP(f()));
/** Constructs an MaybeAsync object from a function that returns a Promise */
exports.liftPromise = (f) => exports.MaybeAsync(f);
/** Constructs an MaybeAsync object from a Maybe */
exports.liftMaybe = (maybe) => exports.MaybeAsync(({ liftMaybe }) => liftMaybe(maybe));
exports.MaybeAsync = Object.assign((runPromise) => new MaybeAsyncImpl(runPromise), {
fromPromise: (f) => exports.MaybeAsync(({ fromPromise: fP }) => fP(f())),
liftPromise: (f) => exports.MaybeAsync(f),
liftMaybe: (maybe) => exports.MaybeAsync(({ liftMaybe }) => liftMaybe(maybe))
});
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NonEmptyList = void 0;
const Maybe_1 = require("./Maybe");

@@ -4,0 +5,0 @@ const NonEmptyListConstructor = (list) => list;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tuple = void 0;
class TupleImpl {

@@ -4,0 +5,0 @@ constructor(first, second) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.orderToNumber = exports.compare = exports.Order = exports.always = exports.identity = void 0;
/** The identity function, returns the value it was given */

@@ -4,0 +5,0 @@ exports.identity = function (x) { return x; };

"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./Codec"));
__export(require("./Either"));
__export(require("./Function"));
__export(require("./List"));
__export(require("./Maybe"));
__exportStar(require("./Codec"), exports);
__exportStar(require("./Either"), exports);
__exportStar(require("./Function"), exports);
__exportStar(require("./List"), exports);
__exportStar(require("./Maybe"), exports);
var MaybeAsync_1 = require("./MaybeAsync");
exports.MaybeAsync = MaybeAsync_1.MaybeAsync;
Object.defineProperty(exports, "MaybeAsync", { enumerable: true, get: function () { return MaybeAsync_1.MaybeAsync; } });
var EitherAsync_1 = require("./EitherAsync");
exports.EitherAsync = EitherAsync_1.EitherAsync;
__export(require("./NonEmptyList"));
__export(require("./Tuple"));
Object.defineProperty(exports, "EitherAsync", { enumerable: true, get: function () { return EitherAsync_1.EitherAsync; } });
__exportStar(require("./NonEmptyList"), exports);
__exportStar(require("./Tuple"), exports);

@@ -23,2 +23,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.List = void 0;
var Tuple_1 = require("./Tuple");

@@ -25,0 +26,0 @@ var Maybe_1 = require("./Maybe");

@@ -13,4 +13,2 @@ import { Either } from './Either';

export interface Maybe<T> {
/** Internal property and subject to breaking changes, please use some of the available methods on the object if you want to access it */
__value: T;
/** Returns true if `this` is `Just`, otherwise it returns false */

@@ -101,3 +99,3 @@ isJust(): this is AlwaysJust;

declare class Nothing implements Maybe<never> {
__value: never;
private __value;
isJust(): boolean;

@@ -104,0 +102,0 @@ isNothing(): boolean;

"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Nothing = exports.Just = exports.Maybe = void 0;
var Either_1 = require("./Either");

@@ -37,3 +49,20 @@ exports.Maybe = {

catMaybes: function (list) {
return list.filter(function (x) { return x.isJust(); }).map(function (x) { return x.__value; });
var e_1, _a;
var res = [];
try {
for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
var e = list_1_1.value;
if (e.isJust()) {
res.push(e.extract());
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (list_1_1 && !list_1_1.done && (_a = list_1.return)) _a.call(list_1);
}
finally { if (e_1) throw e_1.error; }
}
return res;
},

@@ -59,4 +88,4 @@ encase: function (thunk) {

var Just = /** @class */ (function () {
function Just(value) {
this.__value = value;
function Just(__value) {
this.__value = __value;
}

@@ -79,3 +108,3 @@ Just.prototype.isJust = function () {

Just.prototype.equals = function (other) {
return this.__value === other.__value;
return this.extract() === other.extract();
};

@@ -86,3 +115,3 @@ Just.prototype.map = function (f) {

Just.prototype.ap = function (maybeF) {
return maybeF.isNothing() ? nothing : this.map(maybeF.__value);
return maybeF.isJust() ? this.map(maybeF.extract()) : nothing;
};

@@ -189,3 +218,3 @@ Just.prototype.alt = function (_) {

Nothing.prototype.equals = function (other) {
return this.__value === other.__value;
return this.extract() === other.extract();
};

@@ -192,0 +221,0 @@ Nothing.prototype.map = function (_) {

import { Maybe } from './Maybe';
import { EitherAsync } from './EitherAsync';
export interface MaybeAsync<T> {
export interface MaybeAsyncTypeRef {
/** Constructs a MaybeAsync object from a function that takes an object full of helpers that let you lift things into the MaybeAsync context and returns a Promise */
<T>(runPromise: (helpers: MaybeAsyncHelpers) => PromiseLike<T>): MaybeAsync<T>;
/** Constructs an MaybeAsync object from a function that returns a Maybe wrapped in a Promise */
fromPromise<T>(f: () => Promise<Maybe<T>>): MaybeAsync<T>;
/** Constructs an MaybeAsync object from a function that returns a Promise */
liftPromise<T>(f: () => Promise<T>): MaybeAsync<T>;
/** Constructs an MaybeAsync object from a Maybe */
liftMaybe<T>(maybe: Maybe<T>): MaybeAsync<T>;
}
export interface MaybeAsync<T> extends PromiseLike<Maybe<T>> {
/**

@@ -21,7 +31,9 @@ * It's important to remember how `run` will behave because in an

/** Transforms `this` with a function that returns a `MaybeAsync`. Behaviour is the same as the regular Maybe#chain */
chain<U>(f: (value: T) => MaybeAsync<U>): MaybeAsync<U>;
chain<U>(f: (value: T) => PromiseLike<Maybe<U>>): MaybeAsync<U>;
/** Converts `this` to a EitherAsync with a default error value */
toEitherAsync<L>(error: L): EitherAsync<L, T>;
'fantasy-land/map'<U>(f: (value: T) => U): MaybeAsync<U>;
'fantasy-land/chain'<U>(f: (value: T) => MaybeAsync<U>): MaybeAsync<U>;
'fantasy-land/chain'<U>(f: (value: T) => PromiseLike<Maybe<U>>): MaybeAsync<U>;
/** WARNING: This is implemented only for Promise compatibility. Please use `chain` instead. */
then: any;
}

@@ -36,9 +48,2 @@ export interface MaybeAsyncValue<T> extends PromiseLike<T> {

}
/** Constructs a MaybeAsync object from a function that takes an object full of helpers that let you lift things into the MaybeAsync context and returns a Promise */
export declare const MaybeAsync: <T>(runPromise: (helpers: MaybeAsyncHelpers) => PromiseLike<T>) => MaybeAsync<T>;
/** Constructs an MaybeAsync object from a function that returns a Maybe wrapped in a Promise */
export declare const fromPromise: <T>(f: () => Promise<Maybe<T>>) => MaybeAsync<T>;
/** Constructs an MaybeAsync object from a function that returns a Promise */
export declare const liftPromise: <T>(f: () => Promise<T>) => MaybeAsync<T>;
/** Constructs an MaybeAsync object from a Maybe */
export declare const liftMaybe: <T>(maybe: Maybe<T>) => MaybeAsync<T>;
export declare const MaybeAsync: MaybeAsyncTypeRef;

@@ -39,2 +39,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.MaybeAsync = void 0;
var Maybe_1 = require("./Maybe");

@@ -44,6 +45,6 @@ var EitherAsync_1 = require("./EitherAsync");

liftMaybe: function (maybe) {
if (maybe.isNothing()) {
throw Maybe_1.Nothing;
if (maybe.isJust()) {
return Promise.resolve(maybe.extract());
}
return Promise.resolve(maybe.__value);
throw Maybe_1.Nothing;
},

@@ -57,2 +58,3 @@ fromPromise: function (promise) {

this.runPromise = runPromise;
this[Symbol.toStringTag] = 'MaybeAsync';
}

@@ -90,4 +92,3 @@ MaybeAsyncImpl.prototype.run = function () {

value = _a.sent();
return [4 /*yield*/, helpers.fromPromise(f(value).run())];
case 2: return [2 /*return*/, _a.sent()];
return [2 /*return*/, helpers.fromPromise(f(value))];
}

@@ -120,23 +121,21 @@ });

};
MaybeAsyncImpl.prototype.then = function (onfulfilled, onrejected) {
return this.run().then(onfulfilled, onrejected);
};
return MaybeAsyncImpl;
}());
/** Constructs a MaybeAsync object from a function that takes an object full of helpers that let you lift things into the MaybeAsync context and returns a Promise */
exports.MaybeAsync = function (runPromise) { return new MaybeAsyncImpl(runPromise); };
/** Constructs an MaybeAsync object from a function that returns a Maybe wrapped in a Promise */
exports.fromPromise = function (f) {
return exports.MaybeAsync(function (_a) {
var fP = _a.fromPromise;
return fP(f());
});
};
/** Constructs an MaybeAsync object from a function that returns a Promise */
exports.liftPromise = function (f) {
return exports.MaybeAsync(f);
};
/** Constructs an MaybeAsync object from a Maybe */
exports.liftMaybe = function (maybe) {
return exports.MaybeAsync(function (_a) {
var liftMaybe = _a.liftMaybe;
return liftMaybe(maybe);
});
};
exports.MaybeAsync = Object.assign(function (runPromise) { return new MaybeAsyncImpl(runPromise); }, {
fromPromise: function (f) {
return exports.MaybeAsync(function (_a) {
var fP = _a.fromPromise;
return fP(f());
});
},
liftPromise: function (f) { return exports.MaybeAsync(f); },
liftMaybe: function (maybe) {
return exports.MaybeAsync(function (_a) {
var liftMaybe = _a.liftMaybe;
return liftMaybe(maybe);
});
}
});
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NonEmptyList = void 0;
var Maybe_1 = require("./Maybe");

@@ -4,0 +5,0 @@ var NonEmptyListConstructor = function (list) { return list; };

{
"name": "purify-ts",
"version": "0.16.0-beta.2",
"version": "0.16.0-beta.3",
"description": "Functional programming standard library for TypeScript ",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"main": "index.js",
"types": "index.d.ts",
"repository": "https://github.com/gigobyte/purify.git",

@@ -30,7 +30,7 @@ "author": "gigobyte <gigobest2@gmail.com>",

"devDependencies": {
"@types/jest": "^25.1.1",
"jest": "^25.1.0",
"@types/jest": "^26.0.0",
"jest": "26.1.0",
"prettier": "^2.0.1",
"ts-jest": "^25.0.0",
"typescript": "3.9.3"
"ts-jest": "26.1.1",
"typescript": "3.9.6"
},

@@ -37,0 +37,0 @@ "dependencies": {

@@ -44,2 +44,7 @@ <h3 align="center">

# Ecosystem
- [purify-ts-extra-codec](https://github.com/airtoxin/purify-ts-extra-codec) - Extra utility codecs
- [chai-purify](https://github.com/dave-inc/chai-purify) - Chai assert helpers
# Inspired by

@@ -46,0 +51,0 @@

@@ -46,2 +46,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Tuple = void 0;
var TupleImpl = /** @class */ (function () {

@@ -48,0 +49,0 @@ function TupleImpl(first, second) {

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