Socket
Socket
Sign inDemoInstall

@fp-ts/core

Package Overview
Dependencies
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fp-ts/core - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

37

Either.d.ts

@@ -635,5 +635,42 @@ /**

/**
* Extracts the value of an `Either` or throws if the `Either` is `Left`.
*
* If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
*
* @param self - The `Either` to extract the value from.
* @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.
*
* @example
* import * as E from "@fp-ts/core/Either"
*
* assert.deepStrictEqual(
* E.getOrThrowWith(E.right(1), () => new Error('Unexpected Left')),
* 1
* )
* assert.throws(() => E.getOrThrowWith(E.left("error"), () => new Error('Unexpected Left')))
*
* @category interop
* @since 1.0.0
*/
export declare const getOrThrowWith: {
<E>(onLeft: (e: E) => unknown): <A>(self: Either<E, A>) => A;
<E, A>(self: Either<E, A>, onLeft: (e: E) => unknown): A;
};
/**
* Extracts the value of an `Either` or throws if the `Either` is `Left`.
*
* The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.
*
* @param self - The `Either` to extract the value from.
* @throws `Error("getOrThrow called on a Left")`
*
* @example
* import * as E from "@fp-ts/core/Either"
*
* assert.deepStrictEqual(E.getOrThrow(E.right(1)), 1)
* assert.throws(() => E.getOrThrow(E.left("error")))
*
* @category interop
* @since 1.0.0
*/
export declare const getOrThrow: <E, A>(self: Either<E, A>) => A;

@@ -640,0 +677,0 @@ /**

43

Either.js

@@ -6,3 +6,3 @@ "use strict";

});
exports.zipWith = exports.unit = exports.tupled = exports.tuple = exports.traverseTap = exports.traverse = exports.toRefinement = exports.toOption = exports.toArray = exports.tapError = exports.tap = exports.sum = exports.subtract = exports.struct = exports.sequence = exports.rights = exports.right = exports.reverse = exports.orElseFail = exports.orElseEither = exports.orElse = exports.of = exports.multiply = exports.merge = exports.match = exports.mapLeft = exports.map = exports.liftThrowable = exports.liftPredicate = exports.liftOption = exports.liftNullable = exports.lift2 = exports.let = exports.lefts = exports.left = exports.isRight = exports.isLeft = exports.isEither = exports.inspectRight = exports.inspectLeft = exports.getRight = exports.getOrUndefined = exports.getOrThrow = exports.getOrNull = exports.getOrElse = exports.getOptionalSemigroup = exports.getLeft = exports.getFirstRightSemigroup = exports.getFirstLeftSemigroup = exports.getFirstLeftMonoid = exports.getEquivalence = exports.fromOption = exports.fromNullable = exports.fromIterable = exports.flatten = exports.flatMapOption = exports.flatMapNullable = exports.flatMap = exports.flap = exports.firstRightOf = exports.filterMap = exports.filter = exports.exists = exports.divide = exports.contains = exports.composeKleisliArrow = exports.compact = exports.bindTo = exports.bind = exports.bimap = exports.asUnit = exports.as = exports.appendElement = exports.ap = exports.andThenDiscard = exports.andThenBind = exports.andThen = exports.Traversable = exports.SemiProduct = exports.SemiCoproduct = exports.SemiApplicative = exports.SemiAlternative = exports.Product = exports.Pointed = exports.Of = exports.Monad = exports.Invariant = exports.Foldable = exports.FlatMap = exports.Do = exports.Covariant = exports.Chainable = exports.Bicovariant = exports.Applicative = void 0;
exports.zipWith = exports.unit = exports.tupled = exports.tuple = exports.traverseTap = exports.traverse = exports.toRefinement = exports.toOption = exports.toArray = exports.tapError = exports.tap = exports.sum = exports.subtract = exports.struct = exports.sequence = exports.rights = exports.right = exports.reverse = exports.orElseFail = exports.orElseEither = exports.orElse = exports.of = exports.multiply = exports.merge = exports.match = exports.mapLeft = exports.map = exports.liftThrowable = exports.liftPredicate = exports.liftOption = exports.liftNullable = exports.lift2 = exports.let = exports.lefts = exports.left = exports.isRight = exports.isLeft = exports.isEither = exports.inspectRight = exports.inspectLeft = exports.getRight = exports.getOrUndefined = exports.getOrThrowWith = exports.getOrThrow = exports.getOrNull = exports.getOrElse = exports.getOptionalSemigroup = exports.getLeft = exports.getFirstRightSemigroup = exports.getFirstLeftSemigroup = exports.getFirstLeftMonoid = exports.getEquivalence = exports.fromOption = exports.fromNullable = exports.fromIterable = exports.flatten = exports.flatMapOption = exports.flatMapNullable = exports.flatMap = exports.flap = exports.firstRightOf = exports.filterMap = exports.filter = exports.exists = exports.divide = exports.contains = exports.composeKleisliArrow = exports.compact = exports.bindTo = exports.bind = exports.bimap = exports.asUnit = exports.as = exports.appendElement = exports.ap = exports.andThenDiscard = exports.andThenBind = exports.andThen = exports.Traversable = exports.SemiProduct = exports.SemiCoproduct = exports.SemiApplicative = exports.SemiAlternative = exports.Product = exports.Pointed = exports.Of = exports.Monad = exports.Invariant = exports.Foldable = exports.FlatMap = exports.Do = exports.Covariant = exports.Chainable = exports.Bicovariant = exports.Applicative = void 0;
var _Function = /*#__PURE__*/require("@fp-ts/core/Function");

@@ -712,2 +712,18 @@ var _effect = /*#__PURE__*/require("@fp-ts/core/internal/effect");

/**
* Extracts the value of an `Either` or throws if the `Either` is `Left`.
*
* If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
*
* @param self - The `Either` to extract the value from.
* @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.
*
* @example
* import * as E from "@fp-ts/core/Either"
*
* assert.deepStrictEqual(
* E.getOrThrowWith(E.right(1), () => new Error('Unexpected Left')),
* 1
* )
* assert.throws(() => E.getOrThrowWith(E.left("error"), () => new Error('Unexpected Left')))
*
* @category interop

@@ -717,9 +733,28 @@ * @since 1.0.0

exports.flatMapNullable = flatMapNullable;
const getOrThrow = self => {
const getOrThrowWith = /*#__PURE__*/(0, _Function.dual)(2, (self, onLeft) => {
if (isRight(self)) {
return self.right;
}
throw new Error("getOrThrow called on a Left");
};
throw onLeft(self.left);
});
/**
* Extracts the value of an `Either` or throws if the `Either` is `Left`.
*
* The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.
*
* @param self - The `Either` to extract the value from.
* @throws `Error("getOrThrow called on a Left")`
*
* @example
* import * as E from "@fp-ts/core/Either"
*
* assert.deepStrictEqual(E.getOrThrow(E.right(1)), 1)
* assert.throws(() => E.getOrThrow(E.left("error")))
*
* @category interop
* @since 1.0.0
*/
exports.getOrThrowWith = getOrThrowWith;
const getOrThrow = /*#__PURE__*/getOrThrowWith(() => new Error("getOrThrow called on a Left"));
/**
* Lifts a function that may throw to one returning a `Either`.

@@ -726,0 +761,0 @@ *

@@ -13,2 +13,17 @@ /**

/**
* Tests if a value is a `function`.
*
* @param input - The value to test.
*
* @example
* import { isFunction } from '@fp-ts/core/Predicate'
*
* assert.deepStrictEqual(isFunction(isFunction), true)
* assert.deepStrictEqual(isFunction("function"), false)
*
* @category guards
* @since 1.0.0
*/
export declare const isFunction: (input: unknown) => input is Function;
/**
* Creates a function that is both data-last and data-first.

@@ -15,0 +30,0 @@ *

@@ -8,6 +8,21 @@ "use strict";

exports.flow = flow;
exports.identity = exports.hole = void 0;
exports.isFunction = exports.identity = exports.hole = void 0;
exports.pipe = pipe;
exports.untupled = exports.unsafeCoerce = exports.tupled = void 0;
/**
* Tests if a value is a `function`.
*
* @param input - The value to test.
*
* @example
* import { isFunction } from '@fp-ts/core/Predicate'
*
* assert.deepStrictEqual(isFunction(isFunction), true)
* assert.deepStrictEqual(isFunction("function"), false)
*
* @category guards
* @since 1.0.0
*/
const isFunction = input => typeof input === "function";
/**
* Creates a function that is both data-last and data-first.

@@ -17,2 +32,3 @@ *

*/
exports.isFunction = isFunction;
const dual = (dataFirstArity, body) => {

@@ -19,0 +35,0 @@ // @ts-expect-error

3

internal/ReadonlyArray.d.ts
/**
* @since 1.0.0
*/
export {};
import type { NonEmptyReadonlyArray } from "@fp-ts/core/ReadonlyArray";
export declare function isNonEmpty<A>(self: ReadonlyArray<A>): self is NonEmptyReadonlyArray<A>;
//# sourceMappingURL=ReadonlyArray.d.ts.map

@@ -6,12 +6,13 @@ "use strict";

});
exports.isNonEmpty = exports.fromIterable = void 0;
exports.fromIterable = void 0;
exports.isNonEmpty = isNonEmpty;
/**
* @since 1.0.0
*/
function isNonEmpty(self) {
return self.length > 0;
}
/** @internal */
const isNonEmpty = as => as.length > 0;
/** @internal */
exports.isNonEmpty = isNonEmpty;
const fromIterable = collection => Array.isArray(collection) ? collection : Array.from(collection);
exports.fromIterable = fromIterable;
//# sourceMappingURL=ReadonlyArray.js.map

@@ -191,2 +191,24 @@ import type { Ordering } from "@fp-ts/core/Ordering";

export declare const multiplyAll: (collection: Iterable<number>) => number;
/**
* Returns the remainder left over when one operand is divided by a second operand.
*
* It always takes the sign of the dividend.
*
* @param self - The dividend.
* @param divisor - The divisor.
*
* @example
* import { remainder } from "@fp-ts/core/Number"
*
* assert.deepStrictEqual(remainder(2, 2), 0)
* assert.deepStrictEqual(remainder(3, 2), 1)
* assert.deepStrictEqual(remainder(-4, 2), -0)
*
* @category algebraic operations
* @since 1.0.0
*/
export declare const remainder: {
(divisor: number): (self: number) => number;
(self: number, divisor: number): number;
};
//# sourceMappingURL=Number.d.ts.map

@@ -6,3 +6,3 @@ "use strict";

});
exports.sumAll = exports.sum = exports.subtract = exports.sign = exports.multiplyAll = exports.multiply = exports.isNumber = exports.increment = exports.divide = exports.decrement = exports.SemigroupSum = exports.SemigroupMultiply = exports.SemigroupMin = exports.SemigroupMax = exports.Order = exports.MonoidSum = exports.MonoidMultiply = exports.MonoidMin = exports.MonoidMax = exports.Equivalence = exports.Bounded = void 0;
exports.sumAll = exports.sum = exports.subtract = exports.sign = exports.remainder = exports.multiplyAll = exports.multiply = exports.isNumber = exports.increment = exports.divide = exports.decrement = exports.SemigroupSum = exports.SemigroupMultiply = exports.SemigroupMin = exports.SemigroupMax = exports.Order = exports.MonoidSum = exports.MonoidMultiply = exports.MonoidMin = exports.MonoidMax = exports.Equivalence = exports.Bounded = void 0;
var _Function = /*#__PURE__*/require("@fp-ts/core/Function");

@@ -217,2 +217,30 @@ var predicate = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Predicate"));

const multiplyAll = MonoidMultiply.combineAll;
/**
* Returns the remainder left over when one operand is divided by a second operand.
*
* It always takes the sign of the dividend.
*
* @param self - The dividend.
* @param divisor - The divisor.
*
* @example
* import { remainder } from "@fp-ts/core/Number"
*
* assert.deepStrictEqual(remainder(2, 2), 0)
* assert.deepStrictEqual(remainder(3, 2), 1)
* assert.deepStrictEqual(remainder(-4, 2), -0)
*
* @category algebraic operations
* @since 1.0.0
*/
exports.multiplyAll = multiplyAll;
const remainder = /*#__PURE__*/(0, _Function.dual)(2, (self, divisor) => {
// https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
const selfDecCount = (self.toString().split(".")[1] || "").length;
const divisorDecCount = (divisor.toString().split(".")[1] || "").length;
const decCount = selfDecCount > divisorDecCount ? selfDecCount : divisorDecCount;
const selfInt = parseInt(self.toFixed(decCount).replace(".", ""));
const divisorInt = parseInt(divisor.toFixed(decCount).replace(".", ""));
return selfInt % divisorInt / Math.pow(10, decCount);
});
/*

@@ -228,3 +256,3 @@

*/
exports.multiplyAll = multiplyAll;
exports.remainder = remainder;
//# sourceMappingURL=Number.js.map

@@ -440,13 +440,38 @@ /**

/**
* Returns the contained value if the `Option` is `Some`, otherwise throws an error.
* Extracts the value of an `Option` or throws if the `Option` is `None`.
*
* If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
*
* @param self - The `Option` to extract the value from.
* @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.
*
* @example
* import * as O from '@fp-ts/core/Option'
*
* assert.deepStrictEqual(
* O.getOrThrowWith(O.some(1), () => new Error('Unexpected None')),
* 1
* )
* assert.throws(() => O.getOrThrowWith(O.none(), () => new Error('Unexpected None')))
*
* @category interop
* @since 1.0.0
*/
export declare const getOrThrowWith: {
(onNone: () => unknown): <A>(self: Option<A>) => A;
<A>(self: Option<A>, onNone: () => unknown): A;
};
/**
* Extracts the value of an `Option` or throws if the `Option` is `None`.
*
* The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.
*
* @param self - The `Option` to extract the value from.
* @throws `Error("getOrThrow called on a None")`
*
* @example
* import { pipe } from '@fp-ts/core/Function'
* import * as O from '@fp-ts/core/Option'
*
* assert.deepStrictEqual(pipe(O.some(1), O.getOrThrow), 1)
* assert.throws(() => pipe(O.none(), O.getOrThrow))
* assert.deepStrictEqual(O.getOrThrow(O.some(1)), 1)
* assert.throws(() => O.getOrThrow(O.none()))
*

@@ -453,0 +478,0 @@ * @category interop

@@ -6,3 +6,3 @@ "use strict";

});
exports.zipWith = exports.unit = exports.tupled = exports.tuple = exports.traverseTap = exports.traverse = exports.toRefinement = exports.toEither = exports.toArray = exports.tap = exports.sumCompact = exports.sum = exports.subtract = exports.struct = exports.some = exports.sequence = exports.reduceCompact = exports.partitionMap = exports.orElseEither = exports.orElse = exports.of = exports.none = exports.multiplyCompact = exports.multiply = exports.match = exports.map = exports.liftThrowable = exports.liftPredicate = exports.liftNullable = exports.liftEither = exports.lift2 = exports.let = exports.isSome = exports.isOption = exports.isNone = exports.inspectSome = exports.inspectNone = exports.getRight = exports.getOrder = exports.getOrUndefined = exports.getOrThrow = exports.getOrNull = exports.getOrElse = exports.getOptionalMonoid = exports.getLeft = exports.getFirstSomeSemigroup = exports.getFailureSemigroup = exports.getFailureMonoid = exports.getEquivalence = exports.fromNullable = exports.fromIterable = exports.fromEither = exports.flatten = exports.flatMapNullable = exports.flatMapEither = exports.flatMap = exports.flap = exports.firstSomeOf = exports.filterMap = exports.filter = exports.exists = exports.divide = exports.contains = exports.composeKleisliArrow = exports.bindTo = exports.bind = exports.asUnit = exports.as = exports.appendElement = exports.ap = exports.andThenDiscard = exports.andThenBind = exports.andThen = exports.Traversable = exports.SemiProduct = exports.SemiCoproduct = exports.SemiApplicative = exports.SemiAlternative = exports.Product = exports.Pointed = exports.Of = exports.Monad = exports.Invariant = exports.Foldable = exports.FlatMap = exports.Filterable = exports.Do = exports.Covariant = exports.Coproduct = exports.Chainable = exports.Applicative = exports.Alternative = void 0;
exports.zipWith = exports.unit = exports.tupled = exports.tuple = exports.traverseTap = exports.traverse = exports.toRefinement = exports.toEither = exports.toArray = exports.tap = exports.sumCompact = exports.sum = exports.subtract = exports.struct = exports.some = exports.sequence = exports.reduceCompact = exports.partitionMap = exports.orElseEither = exports.orElse = exports.of = exports.none = exports.multiplyCompact = exports.multiply = exports.match = exports.map = exports.liftThrowable = exports.liftPredicate = exports.liftNullable = exports.liftEither = exports.lift2 = exports.let = exports.isSome = exports.isOption = exports.isNone = exports.inspectSome = exports.inspectNone = exports.getRight = exports.getOrder = exports.getOrUndefined = exports.getOrThrowWith = exports.getOrThrow = exports.getOrNull = exports.getOrElse = exports.getOptionalMonoid = exports.getLeft = exports.getFirstSomeSemigroup = exports.getFailureSemigroup = exports.getFailureMonoid = exports.getEquivalence = exports.fromNullable = exports.fromIterable = exports.fromEither = exports.flatten = exports.flatMapNullable = exports.flatMapEither = exports.flatMap = exports.flap = exports.firstSomeOf = exports.filterMap = exports.filter = exports.exists = exports.divide = exports.contains = exports.composeKleisliArrow = exports.bindTo = exports.bind = exports.asUnit = exports.as = exports.appendElement = exports.ap = exports.andThenDiscard = exports.andThenBind = exports.andThen = exports.Traversable = exports.SemiProduct = exports.SemiCoproduct = exports.SemiApplicative = exports.SemiAlternative = exports.Product = exports.Pointed = exports.Of = exports.Monad = exports.Invariant = exports.Foldable = exports.FlatMap = exports.Filterable = exports.Do = exports.Covariant = exports.Coproduct = exports.Chainable = exports.Applicative = exports.Alternative = void 0;
var _Function = /*#__PURE__*/require("@fp-ts/core/Function");

@@ -458,13 +458,17 @@ var _effect = /*#__PURE__*/require("@fp-ts/core/internal/effect");

/**
* Returns the contained value if the `Option` is `Some`, otherwise throws an error.
* Extracts the value of an `Option` or throws if the `Option` is `None`.
*
* If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
*
* @param self - The `Option` to extract the value from.
* @throws `Error("getOrThrow called on a None")`
* @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.
*
* @example
* import { pipe } from '@fp-ts/core/Function'
* import * as O from '@fp-ts/core/Option'
*
* assert.deepStrictEqual(pipe(O.some(1), O.getOrThrow), 1)
* assert.throws(() => pipe(O.none(), O.getOrThrow))
* assert.deepStrictEqual(
* O.getOrThrowWith(O.some(1), () => new Error('Unexpected None')),
* 1
* )
* assert.throws(() => O.getOrThrowWith(O.none(), () => new Error('Unexpected None')))
*

@@ -475,8 +479,27 @@ * @category interop

exports.liftThrowable = liftThrowable;
const getOrThrow = self => {
const getOrThrowWith = /*#__PURE__*/(0, _Function.dual)(2, (self, onNone) => {
if (isSome(self)) {
return self.value;
}
throw new Error("getOrThrow called on a None");
};
throw onNone();
});
/**
* Extracts the value of an `Option` or throws if the `Option` is `None`.
*
* The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.
*
* @param self - The `Option` to extract the value from.
* @throws `Error("getOrThrow called on a None")`
*
* @example
* import * as O from '@fp-ts/core/Option'
*
* assert.deepStrictEqual(O.getOrThrow(O.some(1)), 1)
* assert.throws(() => O.getOrThrow(O.none()))
*
* @category interop
* @since 1.0.0
*/
exports.getOrThrowWith = getOrThrowWith;
const getOrThrow = /*#__PURE__*/getOrThrowWith(() => new Error("getOrThrow called on a None"));
// -------------------------------------------------------------------------------------

@@ -483,0 +506,0 @@ // mapping

{
"name": "@fp-ts/core",
"version": "0.2.0",
"version": "0.2.1",
"license": "MIT",

@@ -5,0 +5,0 @@ "repository": {

@@ -25,2 +25,3 @@ import type { TypeLambda } from "@fp-ts/core/HKT";

/**
* @category models
* @since 1.0.0

@@ -40,2 +41,3 @@ */

* assert.deepStrictEqual(isString("a"), true)
*
* assert.deepStrictEqual(isString(1), false)

@@ -56,2 +58,3 @@ *

* assert.deepStrictEqual(isNumber(2), true)
*
* assert.deepStrictEqual(isNumber("2"), false)

@@ -72,2 +75,3 @@ *

* assert.deepStrictEqual(isBoolean(true), true)
*
* assert.deepStrictEqual(isBoolean("true"), false)

@@ -88,2 +92,3 @@ *

* assert.deepStrictEqual(isBigint(1n), true)
*
* assert.deepStrictEqual(isBigint(1), false)

@@ -104,2 +109,3 @@ *

* assert.deepStrictEqual(isSymbol(Symbol.for("a")), true)
*
* assert.deepStrictEqual(isSymbol("a"), false)

@@ -112,9 +118,256 @@ *

/**
* @category constructors
* Tests if a value is a `function`.
*
* @param input - The value to test.
*
* @example
* import { isFunction } from '@fp-ts/core/Predicate'
*
* assert.deepStrictEqual(isFunction(isFunction), true)
*
* assert.deepStrictEqual(isFunction("function"), false)
*
* @category guards
* @since 1.0.0
*/
export declare const id: <A>() => Refinement<A, A>;
export declare const isFunction: (input: unknown) => input is Function;
/**
* Tests if a value is `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isUndefined } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isUndefined(undefined), true)
*
* assert.deepStrictEqual(isUndefined(null), false)
* assert.deepStrictEqual(isUndefined("undefined"), false)
*
* @category guards
* @since 1.0.0
*/
export declare const isUndefined: (input: unknown) => input is undefined;
/**
* Tests if a value is not `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNotUndefined } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNotUndefined(null), true)
* assert.deepStrictEqual(isNotUndefined("undefined"), true)
*
* assert.deepStrictEqual(isNotUndefined(undefined), false)
*
* @category guards
* @since 1.0.0
*/
export declare const isNotUndefined: <A>(input: A) => input is Exclude<A, undefined>;
/**
* Tests if a value is `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNull } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNull(null), true)
*
* assert.deepStrictEqual(isNull(undefined), false)
* assert.deepStrictEqual(isNull("null"), false)
*
* @category guards
* @since 1.0.0
*/
export declare const isNull: (input: unknown) => input is null;
/**
* Tests if a value is not `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNotNull } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNotNull(undefined), true)
* assert.deepStrictEqual(isNotNull("null"), true)
*
* assert.deepStrictEqual(isNotNull(null), false)
*
* @category guards
* @since 1.0.0
*/
export declare const isNotNull: <A>(input: A) => input is Exclude<A, null>;
/**
* A guard that always fails.
*
* @param _ - The value to test.
*
* @example
* import { isNever } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNever(null), false)
* assert.deepStrictEqual(isNever(undefined), false)
* assert.deepStrictEqual(isNever({}), false)
* assert.deepStrictEqual(isNever([]), false)
*
* @category guards
* @since 1.0.0
*/
export declare const isNever: (input: unknown) => input is never;
/**
* A guard that always succeeds.
*
* @param _ - The value to test.
*
* @example
* import { isUnknown } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isUnknown(null), true)
* assert.deepStrictEqual(isUnknown(undefined), true)
*
* assert.deepStrictEqual(isUnknown({}), true)
* assert.deepStrictEqual(isUnknown([]), true)
*
* @category guards
* @since 1.0.0
*/
export declare const isUnknown: (input: unknown) => input is unknown;
/**
* Tests if a value is an `object`.
*
* @param input - The value to test.
*
* @example
* import { isObject } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isObject({}), true)
* assert.deepStrictEqual(isObject([]), true)
*
* assert.deepStrictEqual(isObject(null), false)
* assert.deepStrictEqual(isObject(undefined), false)
*
* @category guards
* @since 1.0.0
*/
export declare const isObject: (input: unknown) => input is object;
/**
* A guard that succeeds when the input is `null` or `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNullable } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNullable(null), true)
* assert.deepStrictEqual(isNullable(undefined), true)
*
* assert.deepStrictEqual(isNullable({}), false)
* assert.deepStrictEqual(isNullable([]), false)
*
* @category guards
* @since 1.0.0
*/
export declare const isNullable: <A>(input: A) => input is Extract<A, null | undefined>;
/**
* A guard that succeeds when the input is not `null` or `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNotNullable } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNotNullable({}), true)
* assert.deepStrictEqual(isNotNullable([]), true)
*
* assert.deepStrictEqual(isNotNullable(null), false)
* assert.deepStrictEqual(isNotNullable(undefined), false)
*
* @category guards
* @since 1.0.0
*/
export declare const isNotNullable: <A>(input: A) => input is NonNullable<A>;
/**
* A guard that succeeds when the input is an `Error`.
*
* @param input - The value to test.
*
* @example
* import { isError } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isError(new Error()), true)
*
* assert.deepStrictEqual(isError(null), false)
* assert.deepStrictEqual(isError({}), false)
*
* @category guards
* @since 1.0.0
*/
export declare const isError: (input: unknown) => input is Error;
/**
* A guard that succeeds when the input is a `Date`.
*
* @param input - The value to test.
*
* @example
* import { isDate } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isDate(new Date()), true)
*
* assert.deepStrictEqual(isDate(null), false)
* assert.deepStrictEqual(isDate({}), false)
*
* @category guards
* @since 1.0.0
*/
export declare const isDate: (input: unknown) => input is Date;
/**
* A guard that succeeds when the input is a record.
*
* @param input - The value to test.
*
* @example
* import { isRecord } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isRecord({}), true)
* assert.deepStrictEqual(isRecord({ a: 1 }), true)
*
* assert.deepStrictEqual(isRecord([]), false)
* assert.deepStrictEqual(isRecord([1, 2, 3]), false)
* assert.deepStrictEqual(isRecord(null), false)
* assert.deepStrictEqual(isRecord(undefined), false)
*
* @category guards
* @since 1.0.0
*/
export declare const isRecord: (input: unknown) => input is {
[x: string]: unknown;
[x: symbol]: unknown;
};
/**
* A guard that succeeds when the input is a readonly record.
*
* @param input - The value to test.
*
* @example
* import { isReadonlyRecord } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isReadonlyRecord({}), true)
* assert.deepStrictEqual(isReadonlyRecord({ a: 1 }), true)
*
* assert.deepStrictEqual(isReadonlyRecord([]), false)
* assert.deepStrictEqual(isReadonlyRecord([1, 2, 3]), false)
* assert.deepStrictEqual(isReadonlyRecord(null), false)
* assert.deepStrictEqual(isReadonlyRecord(undefined), false)
*
* @category guards
* @since 1.0.0
*/
export declare const isReadonlyRecord: (input: unknown) => input is {
readonly [x: string | symbol]: unknown;
};
/**
* @since 1.0.0
*/
export declare const compose: {

@@ -121,0 +374,0 @@ <A, B extends A, C extends B>(bc: Refinement<B, C>): (ab: Refinement<A, B>) => Refinement<A, C>;

@@ -6,3 +6,3 @@ "use strict";

});
exports.unit = exports.tupled = exports.tuple = exports.struct = exports.or = exports.of = exports.not = exports.isSymbol = exports.isString = exports.isNumber = exports.isBoolean = exports.isBigint = exports.id = exports.getSemigroupAny = exports.getSemigroupAll = exports.getMonoidAny = exports.getMonoidAll = exports.contramap = exports.compose = exports.bindTo = exports.appendElement = exports.any = exports.andThenBind = exports.and = exports.all = exports.SemiProduct = exports.Product = exports.Of = exports.Invariant = exports.Do = exports.Contravariant = void 0;
exports.unit = exports.tupled = exports.tuple = exports.struct = exports.or = exports.of = exports.not = exports.isUnknown = exports.isUndefined = exports.isSymbol = exports.isString = exports.isRecord = exports.isReadonlyRecord = exports.isObject = exports.isNumber = exports.isNullable = exports.isNull = exports.isNotUndefined = exports.isNotNullable = exports.isNotNull = exports.isNever = exports.isFunction = exports.isError = exports.isDate = exports.isBoolean = exports.isBigint = exports.getSemigroupAny = exports.getSemigroupAll = exports.getMonoidAny = exports.getMonoidAll = exports.contramap = exports.compose = exports.bindTo = exports.appendElement = exports.any = exports.andThenBind = exports.and = exports.all = exports.SemiProduct = exports.Product = exports.Of = exports.Invariant = exports.Do = exports.Contravariant = void 0;
var _Function = /*#__PURE__*/require("@fp-ts/core/Function");

@@ -32,2 +32,3 @@ var readonlyArray = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/internal/ReadonlyArray"));

* assert.deepStrictEqual(isString("a"), true)
*
* assert.deepStrictEqual(isString(1), false)

@@ -48,2 +49,3 @@ *

* assert.deepStrictEqual(isNumber(2), true)
*
* assert.deepStrictEqual(isNumber("2"), false)

@@ -65,2 +67,3 @@ *

* assert.deepStrictEqual(isBoolean(true), true)
*
* assert.deepStrictEqual(isBoolean("true"), false)

@@ -82,2 +85,3 @@ *

* assert.deepStrictEqual(isBigint(1n), true)
*
* assert.deepStrictEqual(isBigint(1), false)

@@ -99,2 +103,3 @@ *

* assert.deepStrictEqual(isSymbol(Symbol.for("a")), true)
*
* assert.deepStrictEqual(isSymbol("a"), false)

@@ -108,11 +113,266 @@ *

/**
* @category constructors
* Tests if a value is a `function`.
*
* @param input - The value to test.
*
* @example
* import { isFunction } from '@fp-ts/core/Predicate'
*
* assert.deepStrictEqual(isFunction(isFunction), true)
*
* assert.deepStrictEqual(isFunction("function"), false)
*
* @category guards
* @since 1.0.0
*/
exports.isSymbol = isSymbol;
const id = () => _ => true;
const isFunction = _Function.isFunction;
/**
* Tests if a value is `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isUndefined } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isUndefined(undefined), true)
*
* assert.deepStrictEqual(isUndefined(null), false)
* assert.deepStrictEqual(isUndefined("undefined"), false)
*
* @category guards
* @since 1.0.0
*/
exports.id = id;
exports.isFunction = isFunction;
const isUndefined = input => input === undefined;
/**
* Tests if a value is not `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNotUndefined } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNotUndefined(null), true)
* assert.deepStrictEqual(isNotUndefined("undefined"), true)
*
* assert.deepStrictEqual(isNotUndefined(undefined), false)
*
* @category guards
* @since 1.0.0
*/
exports.isUndefined = isUndefined;
const isNotUndefined = input => input !== undefined;
/**
* Tests if a value is `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNull } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNull(null), true)
*
* assert.deepStrictEqual(isNull(undefined), false)
* assert.deepStrictEqual(isNull("null"), false)
*
* @category guards
* @since 1.0.0
*/
exports.isNotUndefined = isNotUndefined;
const isNull = input => input === null;
/**
* Tests if a value is not `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNotNull } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNotNull(undefined), true)
* assert.deepStrictEqual(isNotNull("null"), true)
*
* assert.deepStrictEqual(isNotNull(null), false)
*
* @category guards
* @since 1.0.0
*/
exports.isNull = isNull;
const isNotNull = input => input !== null;
/**
* A guard that always fails.
*
* @param _ - The value to test.
*
* @example
* import { isNever } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNever(null), false)
* assert.deepStrictEqual(isNever(undefined), false)
* assert.deepStrictEqual(isNever({}), false)
* assert.deepStrictEqual(isNever([]), false)
*
* @category guards
* @since 1.0.0
*/
exports.isNotNull = isNotNull;
const isNever = _ => false;
/**
* A guard that always succeeds.
*
* @param _ - The value to test.
*
* @example
* import { isUnknown } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isUnknown(null), true)
* assert.deepStrictEqual(isUnknown(undefined), true)
*
* assert.deepStrictEqual(isUnknown({}), true)
* assert.deepStrictEqual(isUnknown([]), true)
*
* @category guards
* @since 1.0.0
*/
exports.isNever = isNever;
const isUnknown = _ => true;
/**
* Tests if a value is an `object`.
*
* @param input - The value to test.
*
* @example
* import { isObject } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isObject({}), true)
* assert.deepStrictEqual(isObject([]), true)
*
* assert.deepStrictEqual(isObject(null), false)
* assert.deepStrictEqual(isObject(undefined), false)
*
* @category guards
* @since 1.0.0
*/
exports.isUnknown = isUnknown;
const isObject = input => typeof input === "object" && input != null;
/**
* A guard that succeeds when the input is `null` or `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNullable } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNullable(null), true)
* assert.deepStrictEqual(isNullable(undefined), true)
*
* assert.deepStrictEqual(isNullable({}), false)
* assert.deepStrictEqual(isNullable([]), false)
*
* @category guards
* @since 1.0.0
*/
exports.isObject = isObject;
const isNullable = input => input === null || input === undefined;
/**
* A guard that succeeds when the input is not `null` or `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNotNullable } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNotNullable({}), true)
* assert.deepStrictEqual(isNotNullable([]), true)
*
* assert.deepStrictEqual(isNotNullable(null), false)
* assert.deepStrictEqual(isNotNullable(undefined), false)
*
* @category guards
* @since 1.0.0
*/
exports.isNullable = isNullable;
const isNotNullable = input => input !== null && input !== undefined;
/**
* A guard that succeeds when the input is an `Error`.
*
* @param input - The value to test.
*
* @example
* import { isError } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isError(new Error()), true)
*
* assert.deepStrictEqual(isError(null), false)
* assert.deepStrictEqual(isError({}), false)
*
* @category guards
* @since 1.0.0
*/
exports.isNotNullable = isNotNullable;
const isError = input => input instanceof Error;
/**
* A guard that succeeds when the input is a `Date`.
*
* @param input - The value to test.
*
* @example
* import { isDate } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isDate(new Date()), true)
*
* assert.deepStrictEqual(isDate(null), false)
* assert.deepStrictEqual(isDate({}), false)
*
* @category guards
* @since 1.0.0
*/
exports.isError = isError;
const isDate = input => input instanceof Date;
/**
* A guard that succeeds when the input is a record.
*
* @param input - The value to test.
*
* @example
* import { isRecord } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isRecord({}), true)
* assert.deepStrictEqual(isRecord({ a: 1 }), true)
*
* assert.deepStrictEqual(isRecord([]), false)
* assert.deepStrictEqual(isRecord([1, 2, 3]), false)
* assert.deepStrictEqual(isRecord(null), false)
* assert.deepStrictEqual(isRecord(undefined), false)
*
* @category guards
* @since 1.0.0
*/
exports.isDate = isDate;
const isRecord = input => isObject(input) && !Array.isArray(input);
/**
* A guard that succeeds when the input is a readonly record.
*
* @param input - The value to test.
*
* @example
* import { isReadonlyRecord } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isReadonlyRecord({}), true)
* assert.deepStrictEqual(isReadonlyRecord({ a: 1 }), true)
*
* assert.deepStrictEqual(isReadonlyRecord([]), false)
* assert.deepStrictEqual(isReadonlyRecord([1, 2, 3]), false)
* assert.deepStrictEqual(isReadonlyRecord(null), false)
* assert.deepStrictEqual(isReadonlyRecord(undefined), false)
*
* @category guards
* @since 1.0.0
*/
exports.isRecord = isRecord;
const isReadonlyRecord = isRecord;
/**
* @since 1.0.0
*/
exports.isReadonlyRecord = isReadonlyRecord;
const compose = /*#__PURE__*/(0, _Function.dual)(2, (ab, bc) => a => ab(a) && bc(a));

@@ -152,3 +412,3 @@ /**

exports.tupled = tupled;
const of = _ => id();
const of = _ => isUnknown;
/**

@@ -155,0 +415,0 @@ * @category instances

@@ -27,2 +27,17 @@ <h3 align="center">

## Requirements
- TypeScript 4.8 or newer
- The `strict` flag enabled in your `tsconfig.json` file
```
{
// ...
"compilerOptions": {
// ...
"strict": true,
}
}
```
# Typed functional programming in TypeScript

@@ -29,0 +44,0 @@

@@ -221,5 +221,6 @@ /**

*/
export declare const isEmpty: <A>(self: readonly A[]) => self is readonly [];
export declare function isEmpty<A>(self: Array<A>): self is [];
export declare function isEmpty<A>(self: ReadonlyArray<A>): self is readonly [];
/**
* Determine if a `ReadonlyArray` is empty narrowing down the type to `NonEmptyReadonlyArray`.
* Determine if a `ReadonlyArray` is non empty narrowing down the type to `NonEmptyArray`.
*

@@ -239,3 +240,6 @@ * A `ReadonlyArray` is considered to be a `NonEmptyReadonlyArray` if it contains at least one element.

*/
export declare const isNonEmpty: <A>(self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A>;
export declare const isNonEmpty: {
<A>(self: Array<A>): self is NonEmptyArray<A>;
<A>(self: ReadonlyArray<A>): self is NonEmptyReadonlyArray<A>;
};
/**

@@ -242,0 +246,0 @@ * Return the number of elements in a `ReadonlyArray`.

@@ -8,3 +8,5 @@ "use strict";

exports.every = every;
exports.min = exports.max = exports.matchRight = exports.matchLeft = exports.match = exports.mapNonEmpty = exports.map = exports.makeBy = exports.make = exports.liftPredicate = exports.liftOption = exports.liftNullable = exports.liftMonoid = exports.liftEither = exports.lift2 = exports.let = exports.length = exports.lefts = exports.lastNonEmpty = exports.last = exports.join = exports.isNonEmpty = exports.isEmpty = exports.intersperseNonEmpty = exports.intersperse = exports.intersection = exports.intercalateNonEmpty = exports.intercalate = exports.insertAt = exports.initNonEmpty = exports.init = exports.headNonEmpty = exports.head = exports.groupBy = exports.group = exports.getUnionSemigroup = exports.getUnionMonoid = exports.getSemigroup = exports.getOrder = exports.getMonoid = exports.getIntersectionSemigroup = exports.get = exports.fromOption = exports.fromNullable = exports.fromIterable = exports.fromEither = exports.flattenNonEmpty = exports.flatten = exports.flatMapNullable = exports.flatMapNonEmpty = exports.flatMap = exports.flap = exports.findLastIndex = exports.findLast = exports.findFirstIndex = exports.findFirst = exports.filterMap = exports.filter = exports.extend = void 0;
exports.intersperseNonEmpty = exports.intersperse = exports.intersection = exports.intercalateNonEmpty = exports.intercalate = exports.insertAt = exports.initNonEmpty = exports.init = exports.headNonEmpty = exports.head = exports.groupBy = exports.group = exports.getUnionSemigroup = exports.getUnionMonoid = exports.getSemigroup = exports.getOrder = exports.getMonoid = exports.getIntersectionSemigroup = exports.get = exports.fromOption = exports.fromNullable = exports.fromIterable = exports.fromEither = exports.flattenNonEmpty = exports.flatten = exports.flatMapNullable = exports.flatMapNonEmpty = exports.flatMap = exports.flap = exports.findLastIndex = exports.findLast = exports.findFirstIndex = exports.findFirst = exports.filterMap = exports.filter = exports.extend = void 0;
exports.isEmpty = isEmpty;
exports.min = exports.max = exports.matchRight = exports.matchLeft = exports.match = exports.mapNonEmpty = exports.map = exports.makeBy = exports.make = exports.liftPredicate = exports.liftOption = exports.liftNullable = exports.liftMonoid = exports.liftEither = exports.lift2 = exports.let = exports.length = exports.lefts = exports.lastNonEmpty = exports.last = exports.join = exports.isNonEmpty = void 0;
exports.zipWith = exports.zipNonEmptyWith = exports.zipNonEmpty = exports.zip = exports.unzipNonEmpty = exports.unzip = exports.unsafeGet = exports.unprepend = exports.uniqNonEmpty = exports.uniq = exports.unionNonEmpty = exports.union = exports.unfold = exports.unappend = exports.tupled = exports.traverseTap = exports.traversePartitionMap = exports.traversePartition = exports.traverseNonEmpty = exports.traverseFilterMap = exports.traverseFilter = exports.traverse = exports.takeWhile = exports.takeRight = exports.take = exports.tailNonEmpty = exports.tail = exports.splitNonEmptyAt = exports.splitAt = exports.span = exports.sortNonEmpty = exports.sortByNonEmpty = exports.sortBy = exports.sort = exports.some = exports.setNonEmptyLast = exports.setNonEmptyHead = exports.sequenceNonEmpty = exports.sequence = exports.separate = exports.scanRight = exports.scan = exports.rotateNonEmpty = exports.rotate = exports.rights = exports.reverseNonEmpty = exports.reverse = exports.replicate = exports.replaceOption = exports.replace = exports.remove = exports.reduceRight = exports.reduceKind = exports.reduce = exports.range = exports.prependAllNonEmpty = exports.prependAll = exports.prepend = exports.partitionMap = exports.partition = exports.of = exports.modifyOption = exports.modifyNonEmptyLast = exports.modifyNonEmptyHead = exports.modify = void 0;

@@ -197,20 +199,8 @@ var E = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Either"));

});
/**
* Determine if a `ReadonlyArray` is empty narrowing down the type to `[]`.
*
* @param self - The `ReadonlyArray` to check.
*
* @example
* import { isEmpty } from "@fp-ts/core/ReadonlyArray"
*
* assert.deepStrictEqual(isEmpty([]), true);
* assert.deepStrictEqual(isEmpty([1, 2, 3]), false);
*
* @category guards
* @since 1.0.0
*/
exports.scanRight = scanRight;
const isEmpty = self => self.length === 0;
function isEmpty(self) {
return self.length === 0;
}
/**
* Determine if a `ReadonlyArray` is empty narrowing down the type to `NonEmptyReadonlyArray`.
* Determine if a `ReadonlyArray` is non empty narrowing down the type to `NonEmptyArray`.
*

@@ -230,3 +220,2 @@ * A `ReadonlyArray` is considered to be a `NonEmptyReadonlyArray` if it contains at least one element.

*/
exports.isEmpty = isEmpty;
const isNonEmpty = readonlyArray.isNonEmpty;

@@ -233,0 +222,0 @@ /**

@@ -946,13 +946,53 @@ /**

/**
* Extracts the value of an `Either` or throws if the `Either` is `Left`.
*
* If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
*
* @param self - The `Either` to extract the value from.
* @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.
*
* @example
* import * as E from "@fp-ts/core/Either"
*
* assert.deepStrictEqual(
* E.getOrThrowWith(E.right(1), () => new Error('Unexpected Left')),
* 1
* )
* assert.throws(() => E.getOrThrowWith(E.left("error"), () => new Error('Unexpected Left')))
*
* @category interop
* @since 1.0.0
*/
export const getOrThrow = <E, A>(self: Either<E, A>): A => {
export const getOrThrowWith: {
<E>(onLeft: (e: E) => unknown): <A>(self: Either<E, A>) => A
<E, A>(self: Either<E, A>, onLeft: (e: E) => unknown): A
} = dual(2, <E, A>(self: Either<E, A>, onLeft: (e: E) => unknown): A => {
if (isRight(self)) {
return self.right
}
throw new Error("getOrThrow called on a Left")
}
throw onLeft(self.left)
})
/**
* Extracts the value of an `Either` or throws if the `Either` is `Left`.
*
* The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.
*
* @param self - The `Either` to extract the value from.
* @throws `Error("getOrThrow called on a Left")`
*
* @example
* import * as E from "@fp-ts/core/Either"
*
* assert.deepStrictEqual(E.getOrThrow(E.right(1)), 1)
* assert.throws(() => E.getOrThrow(E.left("error")))
*
* @category interop
* @since 1.0.0
*/
export const getOrThrow: <E, A>(self: Either<E, A>) => A = getOrThrowWith(() =>
new Error("getOrThrow called on a Left")
)
/**
* Lifts a function that may throw to one returning a `Either`.

@@ -959,0 +999,0 @@ *

@@ -19,2 +19,18 @@ /**

/**
* Tests if a value is a `function`.
*
* @param input - The value to test.
*
* @example
* import { isFunction } from '@fp-ts/core/Predicate'
*
* assert.deepStrictEqual(isFunction(isFunction), true)
* assert.deepStrictEqual(isFunction("function"), false)
*
* @category guards
* @since 1.0.0
*/
export const isFunction = (input: unknown): input is Function => typeof input === "function"
/**
* Creates a function that is both data-last and data-first.

@@ -21,0 +37,0 @@ *

@@ -5,6 +5,10 @@ /**

import type { NonEmptyReadonlyArray } from "@fp-ts/core/ReadonlyArray"
import type { NonEmptyArray, NonEmptyReadonlyArray } from "@fp-ts/core/ReadonlyArray"
/** @internal */
export const isNonEmpty = <A>(as: ReadonlyArray<A>): as is NonEmptyReadonlyArray<A> => as.length > 0
export function isNonEmpty<A>(self: Array<A>): self is NonEmptyArray<A>
export function isNonEmpty<A>(self: ReadonlyArray<A>): self is NonEmptyReadonlyArray<A>
export function isNonEmpty<A>(self: ReadonlyArray<A>): self is readonly [] {
return self.length > 0
}

@@ -11,0 +15,0 @@ /** @internal */

@@ -222,2 +222,33 @@ /**

/**
* Returns the remainder left over when one operand is divided by a second operand.
*
* It always takes the sign of the dividend.
*
* @param self - The dividend.
* @param divisor - The divisor.
*
* @example
* import { remainder } from "@fp-ts/core/Number"
*
* assert.deepStrictEqual(remainder(2, 2), 0)
* assert.deepStrictEqual(remainder(3, 2), 1)
* assert.deepStrictEqual(remainder(-4, 2), -0)
*
* @category algebraic operations
* @since 1.0.0
*/
export const remainder: {
(divisor: number): (self: number) => number
(self: number, divisor: number): number
} = dual(2, (self: number, divisor: number): number => {
// https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
const selfDecCount = (self.toString().split(".")[1] || "").length
const divisorDecCount = (divisor.toString().split(".")[1] || "").length
const decCount = selfDecCount > divisorDecCount ? selfDecCount : divisorDecCount
const selfInt = parseInt(self.toFixed(decCount).replace(".", ""))
const divisorInt = parseInt(divisor.toFixed(decCount).replace(".", ""))
return (selfInt % divisorInt) / Math.pow(10, decCount)
})
/*

@@ -224,0 +255,0 @@

@@ -549,13 +549,17 @@ /**

/**
* Returns the contained value if the `Option` is `Some`, otherwise throws an error.
* Extracts the value of an `Option` or throws if the `Option` is `None`.
*
* If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
*
* @param self - The `Option` to extract the value from.
* @throws `Error("getOrThrow called on a None")`
* @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.
*
* @example
* import { pipe } from '@fp-ts/core/Function'
* import * as O from '@fp-ts/core/Option'
*
* assert.deepStrictEqual(pipe(O.some(1), O.getOrThrow), 1)
* assert.throws(() => pipe(O.none(), O.getOrThrow))
* assert.deepStrictEqual(
* O.getOrThrowWith(O.some(1), () => new Error('Unexpected None')),
* 1
* )
* assert.throws(() => O.getOrThrowWith(O.none(), () => new Error('Unexpected None')))
*

@@ -565,9 +569,33 @@ * @category interop

*/
export const getOrThrow = <A>(self: Option<A>): A => {
export const getOrThrowWith: {
(onNone: () => unknown): <A>(self: Option<A>) => A
<A>(self: Option<A>, onNone: () => unknown): A
} = dual(2, <A>(self: Option<A>, onNone: () => unknown): A => {
if (isSome(self)) {
return self.value
}
throw new Error("getOrThrow called on a None")
}
throw onNone()
})
/**
* Extracts the value of an `Option` or throws if the `Option` is `None`.
*
* The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.
*
* @param self - The `Option` to extract the value from.
* @throws `Error("getOrThrow called on a None")`
*
* @example
* import * as O from '@fp-ts/core/Option'
*
* assert.deepStrictEqual(O.getOrThrow(O.some(1)), 1)
* assert.throws(() => O.getOrThrow(O.none()))
*
* @category interop
* @since 1.0.0
*/
export const getOrThrow: <A>(self: Option<A>) => A = getOrThrowWith(() =>
new Error("getOrThrow called on a None")
)
// -------------------------------------------------------------------------------------

@@ -574,0 +602,0 @@ // mapping

/**
* @since 1.0.0
*/
import { constFalse, constTrue, dual } from "@fp-ts/core/Function"
import { constFalse, constTrue, dual, isFunction as isFunction_ } from "@fp-ts/core/Function"
import type { TypeLambda } from "@fp-ts/core/HKT"

@@ -33,2 +33,3 @@ import * as readonlyArray from "@fp-ts/core/internal/ReadonlyArray"

/**
* @category models
* @since 1.0.0

@@ -49,2 +50,3 @@ */

* assert.deepStrictEqual(isString("a"), true)
*
* assert.deepStrictEqual(isString(1), false)

@@ -66,2 +68,3 @@ *

* assert.deepStrictEqual(isNumber(2), true)
*
* assert.deepStrictEqual(isNumber("2"), false)

@@ -83,2 +86,3 @@ *

* assert.deepStrictEqual(isBoolean(true), true)
*
* assert.deepStrictEqual(isBoolean("true"), false)

@@ -100,2 +104,3 @@ *

* assert.deepStrictEqual(isBigint(1n), true)
*
* assert.deepStrictEqual(isBigint(1), false)

@@ -117,2 +122,3 @@ *

* assert.deepStrictEqual(isSymbol(Symbol.for("a")), true)
*
* assert.deepStrictEqual(isSymbol("a"), false)

@@ -126,10 +132,271 @@ *

/**
* @category constructors
* Tests if a value is a `function`.
*
* @param input - The value to test.
*
* @example
* import { isFunction } from '@fp-ts/core/Predicate'
*
* assert.deepStrictEqual(isFunction(isFunction), true)
*
* assert.deepStrictEqual(isFunction("function"), false)
*
* @category guards
* @since 1.0.0
*/
export const id = <A>(): Refinement<A, A> => (_): _ is A => true
export const isFunction: (input: unknown) => input is Function = isFunction_
/**
* Tests if a value is `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isUndefined } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isUndefined(undefined), true)
*
* assert.deepStrictEqual(isUndefined(null), false)
* assert.deepStrictEqual(isUndefined("undefined"), false)
*
* @category guards
* @since 1.0.0
*/
export const isUndefined = (input: unknown): input is undefined => input === undefined
/**
* Tests if a value is not `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNotUndefined } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNotUndefined(null), true)
* assert.deepStrictEqual(isNotUndefined("undefined"), true)
*
* assert.deepStrictEqual(isNotUndefined(undefined), false)
*
* @category guards
* @since 1.0.0
*/
export const isNotUndefined = <A>(input: A): input is Exclude<A, undefined> => input !== undefined
/**
* Tests if a value is `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNull } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNull(null), true)
*
* assert.deepStrictEqual(isNull(undefined), false)
* assert.deepStrictEqual(isNull("null"), false)
*
* @category guards
* @since 1.0.0
*/
export const isNull = (input: unknown): input is null => input === null
/**
* Tests if a value is not `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNotNull } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNotNull(undefined), true)
* assert.deepStrictEqual(isNotNull("null"), true)
*
* assert.deepStrictEqual(isNotNull(null), false)
*
* @category guards
* @since 1.0.0
*/
export const isNotNull = <A>(input: A): input is Exclude<A, null> => input !== null
/**
* A guard that always fails.
*
* @param _ - The value to test.
*
* @example
* import { isNever } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNever(null), false)
* assert.deepStrictEqual(isNever(undefined), false)
* assert.deepStrictEqual(isNever({}), false)
* assert.deepStrictEqual(isNever([]), false)
*
* @category guards
* @since 1.0.0
*/
export const isNever: (input: unknown) => input is never = (_: unknown): _ is never => false
/**
* A guard that always succeeds.
*
* @param _ - The value to test.
*
* @example
* import { isUnknown } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isUnknown(null), true)
* assert.deepStrictEqual(isUnknown(undefined), true)
*
* assert.deepStrictEqual(isUnknown({}), true)
* assert.deepStrictEqual(isUnknown([]), true)
*
* @category guards
* @since 1.0.0
*/
export const isUnknown: (input: unknown) => input is unknown = (_): _ is unknown => true
/**
* Tests if a value is an `object`.
*
* @param input - The value to test.
*
* @example
* import { isObject } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isObject({}), true)
* assert.deepStrictEqual(isObject([]), true)
*
* assert.deepStrictEqual(isObject(null), false)
* assert.deepStrictEqual(isObject(undefined), false)
*
* @category guards
* @since 1.0.0
*/
export const isObject = (input: unknown): input is object =>
typeof input === "object" && input != null
/**
* A guard that succeeds when the input is `null` or `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNullable } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNullable(null), true)
* assert.deepStrictEqual(isNullable(undefined), true)
*
* assert.deepStrictEqual(isNullable({}), false)
* assert.deepStrictEqual(isNullable([]), false)
*
* @category guards
* @since 1.0.0
*/
export const isNullable = <A>(input: A): input is Extract<A, null | undefined> =>
input === null || input === undefined
/**
* A guard that succeeds when the input is not `null` or `undefined`.
*
* @param input - The value to test.
*
* @example
* import { isNotNullable } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isNotNullable({}), true)
* assert.deepStrictEqual(isNotNullable([]), true)
*
* assert.deepStrictEqual(isNotNullable(null), false)
* assert.deepStrictEqual(isNotNullable(undefined), false)
*
* @category guards
* @since 1.0.0
*/
export const isNotNullable = <A>(input: A): input is NonNullable<A> =>
input !== null && input !== undefined
/**
* A guard that succeeds when the input is an `Error`.
*
* @param input - The value to test.
*
* @example
* import { isError } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isError(new Error()), true)
*
* assert.deepStrictEqual(isError(null), false)
* assert.deepStrictEqual(isError({}), false)
*
* @category guards
* @since 1.0.0
*/
export const isError = (input: unknown): input is Error => input instanceof Error
/**
* A guard that succeeds when the input is a `Date`.
*
* @param input - The value to test.
*
* @example
* import { isDate } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isDate(new Date()), true)
*
* assert.deepStrictEqual(isDate(null), false)
* assert.deepStrictEqual(isDate({}), false)
*
* @category guards
* @since 1.0.0
*/
export const isDate = (input: unknown): input is Date => input instanceof Date
/**
* A guard that succeeds when the input is a record.
*
* @param input - The value to test.
*
* @example
* import { isRecord } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isRecord({}), true)
* assert.deepStrictEqual(isRecord({ a: 1 }), true)
*
* assert.deepStrictEqual(isRecord([]), false)
* assert.deepStrictEqual(isRecord([1, 2, 3]), false)
* assert.deepStrictEqual(isRecord(null), false)
* assert.deepStrictEqual(isRecord(undefined), false)
*
* @category guards
* @since 1.0.0
*/
export const isRecord = (input: unknown): input is { [x: string | symbol]: unknown } =>
isObject(input) && !Array.isArray(input)
/**
* A guard that succeeds when the input is a readonly record.
*
* @param input - The value to test.
*
* @example
* import { isReadonlyRecord } from "@fp-ts/core/Predicate"
*
* assert.deepStrictEqual(isReadonlyRecord({}), true)
* assert.deepStrictEqual(isReadonlyRecord({ a: 1 }), true)
*
* assert.deepStrictEqual(isReadonlyRecord([]), false)
* assert.deepStrictEqual(isReadonlyRecord([1, 2, 3]), false)
* assert.deepStrictEqual(isReadonlyRecord(null), false)
* assert.deepStrictEqual(isReadonlyRecord(undefined), false)
*
* @category guards
* @since 1.0.0
*/
export const isReadonlyRecord: (
input: unknown
) => input is { readonly [x: string | symbol]: unknown } = isRecord
/**
* @since 1.0.0
*/
export const compose: {

@@ -182,3 +449,3 @@ <A, B extends A, C extends B>(bc: Refinement<B, C>): (ab: Refinement<A, B>) => Refinement<A, C>

*/
export const of = <A>(_: A): Predicate<A> => id()
export const of = <A>(_: A): Predicate<A> => isUnknown

@@ -185,0 +452,0 @@ /**

@@ -311,37 +311,120 @@ /**

*/
export const liftThrowable = <A extends ReadonlyArray<unknown>, B, E>(
export const liftThrowable: <A extends ReadonlyArray<unknown>, B, E>(
f: (...a: A) => B,
onThrow: (error: unknown) => E
): ((...a: A) => These<E, B>) =>
(...a) => {
try {
return right(f(...a))
} catch (e) {
return left(onThrow(e))
}
}
) => ((...a: A) => These<E, B>) = E.liftThrowable
/**
* Extracts the value of a `These` or throws if the `These` is `Left`.
*
* If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
*
* @param self - The `These` to extract the value from.
* @param onLeft - A function that will be called if the `These` is `Left`. It returns the error to be thrown.
*
* @example
* import * as E from "@fp-ts/core/These"
*
* assert.deepStrictEqual(
* E.getOrThrowWith(E.right(1), () => new Error('Unexpected Left')),
* 1
* )
* assert.deepStrictEqual(
* E.getOrThrowWith(E.both("warning", 1), () => new Error('Unexpected Left')),
* 1
* )
* assert.throws(() => E.getOrThrowWith(E.left("error"), () => new Error('Unexpected Left')))
*
* @category interop
* @since 1.0.0
*/
export const getOrThrow = <E, A>(self: These<E, A>): A => {
export const getOrThrowWith: {
<E>(onLeft: (e: E) => unknown): <A>(self: These<E, A>) => A
<E, A>(self: These<E, A>, onLeft: (e: E) => unknown): A
} = dual(2, <E, A>(self: These<E, A>, onLeft: (e: E) => unknown): A => {
if (isRightOrBoth(self)) {
return self.right
}
throw new Error("getOrThrow called on a Left")
}
throw onLeft(self.left)
})
/**
* Extracts the value of a `These` or throws if the `These` is `Left`.
*
* The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.
*
* @param self - The `These` to extract the value from.
* @throws `Error("getOrThrow called on a Left")`
*
* @example
* import * as T from "@fp-ts/core/These"
*
* assert.deepStrictEqual(T.getOrThrow(T.right(1)), 1)
* assert.deepStrictEqual(T.getOrThrow(T.both("warning", 1)), 1)
* assert.throws(() => T.getOrThrow(T.left("error")))
*
* @category interop
* @since 1.0.0
*/
export const getRightOnlyOrThrow = <E, A>(self: These<E, A>): A => {
export const getOrThrow: <E, A>(self: These<E, A>) => A = getOrThrowWith(() =>
new Error("getOrThrow called on a Left")
)
/**
* Extracts the value of a `These` or throws if the `These` is `Left`.
*
* If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
*
* @param self - The `These` to extract the value from.
* @param onLeft - A function that will be called if the `These` is `Left`. It returns the error to be thrown.
*
* @example
* import * as E from "@fp-ts/core/These"
*
* assert.deepStrictEqual(
* E.getRightOnlyOrThrowWith(
* E.right(1),
* () => new Error("Unexpected Left or Both")
* ),
* 1
* )
* assert.throws(() => E.getRightOnlyOrThrowWith(E.both("warning", 1), () => new Error("Unexpected Left or Both")))
* assert.throws(() => E.getRightOnlyOrThrowWith(E.left("error"), () => new Error("Unexpected Left or Both")))
*
* @category interop
* @since 1.0.0
*/
export const getRightOnlyOrThrowWith: {
<E>(onLeftOrBoth: (e: E) => unknown): <A>(self: These<E, A>) => A
<E, A>(self: These<E, A>, onLeftOrBoth: (e: E) => unknown): A
} = dual(2, <E, A>(self: These<E, A>, onLeftOrBoth: (e: E) => unknown): A => {
if (isRight(self)) {
return self.right
}
throw new Error("getRightOnlyOrThrow called on Left or Both")
}
throw onLeftOrBoth(self.left)
})
/**
* Extracts the value of a `These` or throws if the `These` is not a `Right`.
*
* The thrown error is a default error. To configure the error thrown, see {@link getRightOnlyOrThrowWith}.
*
* @param self - The `These` to extract the value from.
* @throws `Error("getOrThrow called on a Left")`
*
* @example
* import * as T from "@fp-ts/core/These"
*
* assert.deepStrictEqual(T.getRightOnlyOrThrow(T.right(1)), 1)
* assert.throws(() => T.getRightOnlyOrThrow(T.both("error", 1)))
* assert.throws(() => T.getRightOnlyOrThrow(T.left("error")))
*
* @category interop
* @since 1.0.0
*/
export const getRightOnlyOrThrow: <E, A>(self: These<E, A>) => A = getRightOnlyOrThrowWith(() =>
new Error("getRightOnlyOrThrow called on a Left or a Both")
)
/**
* @category conversions

@@ -348,0 +431,0 @@ * @since 1.0.0

@@ -223,12 +223,96 @@ /**

*/
export declare const liftThrowable: <A extends readonly unknown[], B, E>(f: (...a: A) => B, onThrow: (error: unknown) => E) => (...a: A) => These<E, B>;
export declare const liftThrowable: <A extends ReadonlyArray<unknown>, B, E>(f: (...a: A) => B, onThrow: (error: unknown) => E) => ((...a: A) => These<E, B>);
/**
* Extracts the value of a `These` or throws if the `These` is `Left`.
*
* If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
*
* @param self - The `These` to extract the value from.
* @param onLeft - A function that will be called if the `These` is `Left`. It returns the error to be thrown.
*
* @example
* import * as E from "@fp-ts/core/These"
*
* assert.deepStrictEqual(
* E.getOrThrowWith(E.right(1), () => new Error('Unexpected Left')),
* 1
* )
* assert.deepStrictEqual(
* E.getOrThrowWith(E.both("warning", 1), () => new Error('Unexpected Left')),
* 1
* )
* assert.throws(() => E.getOrThrowWith(E.left("error"), () => new Error('Unexpected Left')))
*
* @category interop
* @since 1.0.0
*/
export declare const getOrThrowWith: {
<E>(onLeft: (e: E) => unknown): <A>(self: These<E, A>) => A;
<E, A>(self: These<E, A>, onLeft: (e: E) => unknown): A;
};
/**
* Extracts the value of a `These` or throws if the `These` is `Left`.
*
* The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.
*
* @param self - The `These` to extract the value from.
* @throws `Error("getOrThrow called on a Left")`
*
* @example
* import * as T from "@fp-ts/core/These"
*
* assert.deepStrictEqual(T.getOrThrow(T.right(1)), 1)
* assert.deepStrictEqual(T.getOrThrow(T.both("warning", 1)), 1)
* assert.throws(() => T.getOrThrow(T.left("error")))
*
* @category interop
* @since 1.0.0
*/
export declare const getOrThrow: <E, A>(self: These<E, A>) => A;
/**
* Extracts the value of a `These` or throws if the `These` is `Left`.
*
* If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
*
* @param self - The `These` to extract the value from.
* @param onLeft - A function that will be called if the `These` is `Left`. It returns the error to be thrown.
*
* @example
* import * as E from "@fp-ts/core/These"
*
* assert.deepStrictEqual(
* E.getRightOnlyOrThrowWith(
* E.right(1),
* () => new Error("Unexpected Left or Both")
* ),
* 1
* )
* assert.throws(() => E.getRightOnlyOrThrowWith(E.both("warning", 1), () => new Error("Unexpected Left or Both")))
* assert.throws(() => E.getRightOnlyOrThrowWith(E.left("error"), () => new Error("Unexpected Left or Both")))
*
* @category interop
* @since 1.0.0
*/
export declare const getRightOnlyOrThrowWith: {
<E>(onLeftOrBoth: (e: E) => unknown): <A>(self: These<E, A>) => A;
<E, A>(self: These<E, A>, onLeftOrBoth: (e: E) => unknown): A;
};
/**
* Extracts the value of a `These` or throws if the `These` is not a `Right`.
*
* The thrown error is a default error. To configure the error thrown, see {@link getRightOnlyOrThrowWith}.
*
* @param self - The `These` to extract the value from.
* @throws `Error("getOrThrow called on a Left")`
*
* @example
* import * as T from "@fp-ts/core/These"
*
* assert.deepStrictEqual(T.getRightOnlyOrThrow(T.right(1)), 1)
* assert.throws(() => T.getRightOnlyOrThrow(T.both("error", 1)))
* assert.throws(() => T.getRightOnlyOrThrow(T.left("error")))
*
* @category interop
* @since 1.0.0
*/
export declare const getRightOnlyOrThrow: <E, A>(self: These<E, A>) => A;

@@ -235,0 +319,0 @@ /**

@@ -6,4 +6,4 @@ "use strict";

});
exports.sequence = exports.rightOrBoth = exports.right = exports.reverse = exports.orElseFail = exports.orElseEither = exports.orElse = exports.of = exports.multiply = exports.match = exports.mapLeft = exports.map = exports.liftThrowable = exports.liftThese = exports.liftPredicate = exports.liftOption = exports.liftNullable = exports.liftEither = exports.lift2 = exports.let = exports.leftOrBoth = exports.left = exports.isThese = exports.isRightOrBoth = exports.isRight = exports.isLeftOrBoth = exports.isLeft = exports.isBoth = exports.inspectRightOrBoth = exports.inspectRight = exports.inspectLeft = exports.inspectBoth = exports.getRightOnlyOrThrow = exports.getRightOnly = exports.getRight = exports.getOrUndefined = exports.getOrThrow = exports.getOrNull = exports.getOrElse = exports.getLeftOnly = exports.getLeft = exports.getFirstRightOrBothSemigroup = exports.getFirstLeftSemigroup = exports.getFirstLeftMonoid = exports.getEquivalence = exports.getBothOrElse = exports.getBoth = exports.fromTuple = exports.fromOption = exports.fromNullable = exports.fromIterable = exports.fromEither = exports.flatten = exports.flatMapThese = exports.flatMapOption = exports.flatMapNullable = exports.flatMapEither = exports.flatMap = exports.flap = exports.firstRightOrBothOf = exports.filterMap = exports.filter = exports.fail = exports.exists = exports.divide = exports.contains = exports.condemn = exports.composeKleisliArrow = exports.compact = exports.both = exports.bindTo = exports.bindThese = exports.bindEither = exports.bind = exports.bimap = exports.asUnit = exports.as = exports.appendElement = exports.ap = exports.andThenDiscard = exports.andThenBind = exports.andThen = exports.absolve = exports.Traversable = exports.SemiProduct = exports.SemiCoproduct = exports.SemiApplicative = exports.SemiAlternative = exports.Product = exports.Pointed = exports.Of = exports.Monad = exports.Invariant = exports.Foldable = exports.FlatMap = exports.Do = exports.Covariant = exports.Chainable = exports.Bicovariant = exports.Applicative = void 0;
exports.zipWith = exports.warn = exports.unit = exports.tupled = exports.tuple = exports.traverseTap = exports.traverse = exports.toValidated = exports.toEither = exports.tap = exports.sum = exports.subtract = exports.struct = void 0;
exports.right = exports.reverse = exports.orElseFail = exports.orElseEither = exports.orElse = exports.of = exports.multiply = exports.match = exports.mapLeft = exports.map = exports.liftThrowable = exports.liftThese = exports.liftPredicate = exports.liftOption = exports.liftNullable = exports.liftEither = exports.lift2 = exports.let = exports.leftOrBoth = exports.left = exports.isThese = exports.isRightOrBoth = exports.isRight = exports.isLeftOrBoth = exports.isLeft = exports.isBoth = exports.inspectRightOrBoth = exports.inspectRight = exports.inspectLeft = exports.inspectBoth = exports.getRightOnlyOrThrowWith = exports.getRightOnlyOrThrow = exports.getRightOnly = exports.getRight = exports.getOrUndefined = exports.getOrThrowWith = exports.getOrThrow = exports.getOrNull = exports.getOrElse = exports.getLeftOnly = exports.getLeft = exports.getFirstRightOrBothSemigroup = exports.getFirstLeftSemigroup = exports.getFirstLeftMonoid = exports.getEquivalence = exports.getBothOrElse = exports.getBoth = exports.fromTuple = exports.fromOption = exports.fromNullable = exports.fromIterable = exports.fromEither = exports.flatten = exports.flatMapThese = exports.flatMapOption = exports.flatMapNullable = exports.flatMapEither = exports.flatMap = exports.flap = exports.firstRightOrBothOf = exports.filterMap = exports.filter = exports.fail = exports.exists = exports.divide = exports.contains = exports.condemn = exports.composeKleisliArrow = exports.compact = exports.both = exports.bindTo = exports.bindThese = exports.bindEither = exports.bind = exports.bimap = exports.asUnit = exports.as = exports.appendElement = exports.ap = exports.andThenDiscard = exports.andThenBind = exports.andThen = exports.absolve = exports.Traversable = exports.SemiProduct = exports.SemiCoproduct = exports.SemiApplicative = exports.SemiAlternative = exports.Product = exports.Pointed = exports.Of = exports.Monad = exports.Invariant = exports.Foldable = exports.FlatMap = exports.Do = exports.Covariant = exports.Chainable = exports.Bicovariant = exports.Applicative = void 0;
exports.zipWith = exports.warn = exports.unit = exports.tupled = exports.tuple = exports.traverseTap = exports.traverse = exports.toValidated = exports.toEither = exports.tap = exports.sum = exports.subtract = exports.struct = exports.sequence = exports.rightOrBoth = void 0;
var E = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Either"));

@@ -221,10 +221,24 @@ var _Function = /*#__PURE__*/require("@fp-ts/core/Function");

exports.isBoth = isBoth;
const liftThrowable = (f, onThrow) => (...a) => {
try {
return right(f(...a));
} catch (e) {
return left(onThrow(e));
}
};
const liftThrowable = E.liftThrowable;
/**
* Extracts the value of a `These` or throws if the `These` is `Left`.
*
* If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
*
* @param self - The `These` to extract the value from.
* @param onLeft - A function that will be called if the `These` is `Left`. It returns the error to be thrown.
*
* @example
* import * as E from "@fp-ts/core/These"
*
* assert.deepStrictEqual(
* E.getOrThrowWith(E.right(1), () => new Error('Unexpected Left')),
* 1
* )
* assert.deepStrictEqual(
* E.getOrThrowWith(E.both("warning", 1), () => new Error('Unexpected Left')),
* 1
* )
* assert.throws(() => E.getOrThrowWith(E.left("error"), () => new Error('Unexpected Left')))
*
* @category interop

@@ -234,20 +248,80 @@ * @since 1.0.0

exports.liftThrowable = liftThrowable;
const getOrThrow = self => {
const getOrThrowWith = /*#__PURE__*/(0, _Function.dual)(2, (self, onLeft) => {
if (isRightOrBoth(self)) {
return self.right;
}
throw new Error("getOrThrow called on a Left");
};
throw onLeft(self.left);
});
/**
* Extracts the value of a `These` or throws if the `These` is `Left`.
*
* The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.
*
* @param self - The `These` to extract the value from.
* @throws `Error("getOrThrow called on a Left")`
*
* @example
* import * as T from "@fp-ts/core/These"
*
* assert.deepStrictEqual(T.getOrThrow(T.right(1)), 1)
* assert.deepStrictEqual(T.getOrThrow(T.both("warning", 1)), 1)
* assert.throws(() => T.getOrThrow(T.left("error")))
*
* @category interop
* @since 1.0.0
*/
exports.getOrThrowWith = getOrThrowWith;
const getOrThrow = /*#__PURE__*/getOrThrowWith(() => new Error("getOrThrow called on a Left"));
/**
* Extracts the value of a `These` or throws if the `These` is `Left`.
*
* If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
*
* @param self - The `These` to extract the value from.
* @param onLeft - A function that will be called if the `These` is `Left`. It returns the error to be thrown.
*
* @example
* import * as E from "@fp-ts/core/These"
*
* assert.deepStrictEqual(
* E.getRightOnlyOrThrowWith(
* E.right(1),
* () => new Error("Unexpected Left or Both")
* ),
* 1
* )
* assert.throws(() => E.getRightOnlyOrThrowWith(E.both("warning", 1), () => new Error("Unexpected Left or Both")))
* assert.throws(() => E.getRightOnlyOrThrowWith(E.left("error"), () => new Error("Unexpected Left or Both")))
*
* @category interop
* @since 1.0.0
*/
exports.getOrThrow = getOrThrow;
const getRightOnlyOrThrow = self => {
const getRightOnlyOrThrowWith = /*#__PURE__*/(0, _Function.dual)(2, (self, onLeftOrBoth) => {
if (isRight(self)) {
return self.right;
}
throw new Error("getRightOnlyOrThrow called on Left or Both");
};
throw onLeftOrBoth(self.left);
});
/**
* Extracts the value of a `These` or throws if the `These` is not a `Right`.
*
* The thrown error is a default error. To configure the error thrown, see {@link getRightOnlyOrThrowWith}.
*
* @param self - The `These` to extract the value from.
* @throws `Error("getOrThrow called on a Left")`
*
* @example
* import * as T from "@fp-ts/core/These"
*
* assert.deepStrictEqual(T.getRightOnlyOrThrow(T.right(1)), 1)
* assert.throws(() => T.getRightOnlyOrThrow(T.both("error", 1)))
* assert.throws(() => T.getRightOnlyOrThrow(T.left("error")))
*
* @category interop
* @since 1.0.0
*/
exports.getRightOnlyOrThrowWith = getRightOnlyOrThrowWith;
const getRightOnlyOrThrow = /*#__PURE__*/getRightOnlyOrThrowWith(() => new Error("getRightOnlyOrThrow called on a Left or a Both"));
/**
* @category conversions

@@ -254,0 +328,0 @@ * @since 1.0.0

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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