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

@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.0.11 to 0.1.0

Bigint.d.ts

106

index.d.ts

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

import * as hkt from "@fp-ts/core/HKT";
import * as bigint from "@fp-ts/core/Bigint";
import * as boolean from "@fp-ts/core/Boolean";
import * as either from "@fp-ts/core/Either";
import * as _function from "@fp-ts/core/Function";
import * as identity from "@fp-ts/core/Identity";
import * as number from "@fp-ts/core/Number";
import * as option from "@fp-ts/core/Option";
import * as ordering from "@fp-ts/core/Ordering";
import * as predicate from "@fp-ts/core/Predicate";
import * as readonlyArray from "@fp-ts/core/ReadonlyArray";
import * as readonlyRecord from "@fp-ts/core/ReadonlyRecord";
import * as string from "@fp-ts/core/String";
import * as struct from "@fp-ts/core/Struct";
import * as symbol from "@fp-ts/core/Symbol";
import * as these from "@fp-ts/core/These";
import * as tuple from "@fp-ts/core/Tuple";
import * as alternative from "@fp-ts/core/typeclass/Alternative";

@@ -11,5 +27,8 @@ import * as applicative from "@fp-ts/core/typeclass/Applicative";

import * as chainable from "@fp-ts/core/typeclass/Chainable";
import * as compactable from "@fp-ts/core/typeclass/Compactable";
import * as contravariant from "@fp-ts/core/typeclass/Contravariant";
import * as coproduct from "@fp-ts/core/typeclass/Coproduct";
import * as covariant from "@fp-ts/core/typeclass/Covariant";
import * as equivalence from "@fp-ts/core/typeclass/Equivalence";
import * as filterable from "@fp-ts/core/typeclass/Filterable";
import * as flatMap from "@fp-ts/core/typeclass/FlatMap";

@@ -20,3 +39,2 @@ import * as foldable from "@fp-ts/core/typeclass/Foldable";

import * as monoid from "@fp-ts/core/typeclass/Monoid";
import * as nonEmptyTraversable from "@fp-ts/core/typeclass/NonEmptyTraversable";
import * as of from "@fp-ts/core/typeclass/Of";

@@ -32,4 +50,9 @@ import * as order from "@fp-ts/core/typeclass/Order";

import * as traversable from "@fp-ts/core/typeclass/Traversable";
import * as traversableFilterable from "@fp-ts/core/typeclass/TraversableFilterable";
export {
/**
* @since 1.0.0
*/
_function as function,
/**
* @category typeclass

@@ -50,2 +73,10 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
bigint,
/**
* @since 1.0.0
*/
boolean,
/**
* @category typeclass

@@ -64,2 +95,7 @@ * @since 1.0.0

*/
compactable,
/**
* @category typeclass
* @since 1.0.0
*/
contravariant,

@@ -77,5 +113,19 @@ /**

/**
* @since 1.0.0
*/
either,
/**
* @category typeclass
* @since 1.0.0
*/
equivalence,
/**
* @category typeclass
* @since 1.0.0
*/
filterable,
/**
* @category typeclass
* @since 1.0.0
*/
flatMap,

@@ -92,2 +142,6 @@ /**

/**
* @since 1.0.0
*/
identity,
/**
* @category typeclass

@@ -108,6 +162,5 @@ * @since 1.0.0

/**
* @category typeclass
* @since 1.0.0
*/
nonEmptyTraversable,
number,
/**

@@ -119,2 +172,6 @@ * @category typeclass

/**
* @since 1.0.0
*/
option,
/**
* @category typeclass

@@ -125,2 +182,6 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
ordering,
/**
* @category typeclass

@@ -131,2 +192,6 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
predicate,
/**
* @category typeclass

@@ -137,2 +202,10 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
readonlyArray,
/**
* @since 1.0.0
*/
readonlyRecord,
/**
* @category typeclass

@@ -163,6 +236,31 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
string,
/**
* @since 1.0.0
*/
struct,
/**
* @since 1.0.0
*/
symbol,
/**
* @since 1.0.0
*/
these,
/**
* @category typeclass
* @since 1.0.0
*/
traversable };
traversable,
/**
* @category typeclass
* @since 1.0.0
*/
traversableFilterable,
/**
* @since 1.0.0
*/
tuple };
//# sourceMappingURL=index.d.ts.map

@@ -6,5 +6,37 @@ "use strict";

});
exports.traversable = exports.semigroup = exports.semiProduct = exports.semiCoproduct = exports.semiApplicative = exports.semiAlternative = exports.product = exports.pointed = exports.order = exports.of = exports.nonEmptyTraversable = exports.monoid = exports.monad = exports.invariant = exports.hkt = exports.foldable = exports.flatMap = exports.covariant = exports.coproduct = exports.contravariant = exports.chainable = exports.bounded = exports.bicovariant = exports.applicative = exports.alternative = void 0;
exports.tuple = exports.traversableFilterable = exports.traversable = exports.these = exports.symbol = exports.struct = exports.string = exports.semigroup = exports.semiProduct = exports.semiCoproduct = exports.semiApplicative = exports.semiAlternative = exports.readonlyRecord = exports.readonlyArray = exports.product = exports.predicate = exports.pointed = exports.ordering = exports.order = exports.option = exports.of = exports.number = exports.monoid = exports.monad = exports.invariant = exports.identity = exports.hkt = exports.function = exports.foldable = exports.flatMap = exports.filterable = exports.equivalence = exports.either = exports.covariant = exports.coproduct = exports.contravariant = exports.compactable = exports.chainable = exports.bounded = exports.boolean = exports.bigint = exports.bicovariant = exports.applicative = exports.alternative = void 0;
var hkt = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/HKT"));
exports.hkt = hkt;
var bigint = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Bigint"));
exports.bigint = bigint;
var boolean = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Boolean"));
exports.boolean = boolean;
var either = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Either"));
exports.either = either;
var _function = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Function"));
exports.function = _function;
var identity = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Identity"));
exports.identity = identity;
var number = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Number"));
exports.number = number;
var option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Option"));
exports.option = option;
var ordering = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Ordering"));
exports.ordering = ordering;
var predicate = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Predicate"));
exports.predicate = predicate;
var readonlyArray = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/ReadonlyArray"));
exports.readonlyArray = readonlyArray;
var readonlyRecord = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/ReadonlyRecord"));
exports.readonlyRecord = readonlyRecord;
var string = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/String"));
exports.string = string;
var struct = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Struct"));
exports.struct = struct;
var symbol = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Symbol"));
exports.symbol = symbol;
var these = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/These"));
exports.these = these;
var tuple = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/Tuple"));
exports.tuple = tuple;
var alternative = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/Alternative"));

@@ -20,2 +52,4 @@ exports.alternative = alternative;

exports.chainable = chainable;
var compactable = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/Compactable"));
exports.compactable = compactable;
var contravariant = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/Contravariant"));

@@ -27,2 +61,6 @@ exports.contravariant = contravariant;

exports.covariant = covariant;
var equivalence = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/Equivalence"));
exports.equivalence = equivalence;
var filterable = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/Filterable"));
exports.filterable = filterable;
var flatMap = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/FlatMap"));

@@ -38,4 +76,2 @@ exports.flatMap = flatMap;

exports.monoid = monoid;
var nonEmptyTraversable = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/NonEmptyTraversable"));
exports.nonEmptyTraversable = nonEmptyTraversable;
var of = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/Of"));

@@ -61,4 +97,6 @@ exports.of = of;

exports.traversable = traversable;
var traversableFilterable = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/TraversableFilterable"));
exports.traversableFilterable = traversableFilterable;
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
//# sourceMappingURL=index.js.map

2

package.json
{
"name": "@fp-ts/core",
"version": "0.0.11",
"version": "0.1.0",
"license": "MIT",

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

@@ -19,5 +19,5 @@ <h3 align="center">

This project represents the next major iteration of [`fp-ts`](https://github.com/gcanti/fp-ts) and it's objective is a reconciliation with [`Effect`](https://github.com/Effect-TS) in order to unify the ecosystems.
This project represents the next major iteration of [`fp-ts`](https://github.com/gcanti/fp-ts) and it's objective is a reconciliation with [`@effect`](https://github.com/Effect-TS) in order to unify the ecosystems.
The [`Effect`](https://github.com/Effect-TS) project will reduce it's scope to simply being an effect system and will delegate to `fp-ts org` all the lower level abstractions such as typeclasses and common data structures.
The [`@effect`](https://github.com/Effect-TS) project will reduce it's scope to simply being an effect system and will delegate to `fp-ts org` all the lower level abstractions such as typeclasses and common data structures.

@@ -28,18 +28,17 @@ The objective of the `fp-ts org` in github and in npm (`@fp-ts`) is to simplify structure and management of the project, have smaller and better scoped packages.

- `@fp-ts/core` with the new `HKT` implementation and the most common typeclasses such as `Monad`
- `@fp-ts/data` with `Option`, `Either`, `ReadonlyArray`, `List` and the most common data structures together with data related typeclasses (i.e. `Compactable`, etc)
- `@fp-ts/optics` with an optic implementation that will provide also optics for structures in `@fp-ts/data`
- `@fp-ts/codec` with a concrete codec such as `io-ts` again for all the structures in `@fp-ts/data`
- The [`@fp-ts/core`](https://github.com/fp-ts/core) library features a new implementation of the Higher Kinded Type (HKT) pattern, including common typeclasses such as `Monad` and widely-used data types like `Option`, `Either`, and `ReadonlyArray`
- [`@fp-ts/schema`](https://github.com/fp-ts/schema) offers schema validation with static type inference, including decoders for data structures in `@fp-ts/core` and `@effect/data`
- [`@fp-ts/optic`](https://github.com/fp-ts/optic) provides optics for structures in both `@fp-ts/core` and `@effect/data`
And for [`Effect`](https://github.com/Effect-TS) to have:
For those using [`fp-ts`](https://github.com/gcanti/fp-ts) v2 and its ecosystem, roughly these are the equivalents:
- `@effect/core` with the effect system
- `@effect/query` with the query impl
- `@effect/*` every other effect based impl
- [`fp-ts`](https://github.com/gcanti/fp-ts) -> [`@fp-ts/core`](https://github.com/fp-ts/core) + [`@effect/*` packages](https://github.com/Effect-TS)
- [`io-ts`](https://github.com/gcanti/io-ts) -> [`@fp-ts/schema`](https://github.com/fp-ts/schema)
- [`monocle-ts`](https://github.com/gcanti/monocle-ts) -> [`@fp-ts/optic`](https://github.com/fp-ts/optic)
Note that [`Effect`](https://github.com/Effect-TS) will not have base structures like `Option` / `Either` / `List` and typeclasses like `Monad` / `Functor` and [`fp-ts`](https://github.com/fp-ts) will not have effect execution modules like `Task` / `IO` as both projects are made to be the same ecosystem and each answer a specific set of needs in the best way possible.
Note that `@fp-ts/core` will not contain any effect system (e.g. `Task`, `TaskEither`, `ReaderTaskEither`) since the handling of effects is entirely delegated to the packages contained in [`@effect/*`](https://github.com/Effect-TS).
# Installation
To install the **pre-alpha** version:
To install the **alpha** version:

@@ -52,3 +51,6 @@ ```

- [Overview](./Overview.md)
- [Typeclass overview](./typeclass.md)
- [Data overview](./data.md)
- [The `Option` data type](./Option.md)
- [The `Either` data type](./Either.md)
- [API Reference](https://fp-ts.github.io/core/)

@@ -55,0 +57,0 @@

@@ -12,2 +12,23 @@ /**

// -------------------------------------------------------------------------------------
// data types
// -------------------------------------------------------------------------------------
import * as bigint from "@fp-ts/core/Bigint"
import * as boolean from "@fp-ts/core/Boolean"
import * as either from "@fp-ts/core/Either"
import * as _function from "@fp-ts/core/Function"
import * as identity from "@fp-ts/core/Identity"
import * as number from "@fp-ts/core/Number"
import * as option from "@fp-ts/core/Option"
import * as ordering from "@fp-ts/core/Ordering"
import * as predicate from "@fp-ts/core/Predicate"
import * as readonlyArray from "@fp-ts/core/ReadonlyArray"
import * as readonlyRecord from "@fp-ts/core/ReadonlyRecord"
import * as string from "@fp-ts/core/String"
import * as struct from "@fp-ts/core/Struct"
import * as symbol from "@fp-ts/core/Symbol"
import * as these from "@fp-ts/core/These"
import * as tuple from "@fp-ts/core/Tuple"
// -------------------------------------------------------------------------------------
// typeclasses

@@ -21,5 +42,8 @@ // -------------------------------------------------------------------------------------

import * as chainable from "@fp-ts/core/typeclass/Chainable"
import * as compactable from "@fp-ts/core/typeclass/Compactable"
import * as contravariant from "@fp-ts/core/typeclass/Contravariant"
import * as coproduct from "@fp-ts/core/typeclass/Coproduct"
import * as covariant from "@fp-ts/core/typeclass/Covariant"
import * as equivalence from "@fp-ts/core/typeclass/Equivalence"
import * as filterable from "@fp-ts/core/typeclass/Filterable"
import * as flatMap from "@fp-ts/core/typeclass/FlatMap"

@@ -30,3 +54,2 @@ import * as foldable from "@fp-ts/core/typeclass/Foldable"

import * as monoid from "@fp-ts/core/typeclass/Monoid"
import * as nonEmptyTraversable from "@fp-ts/core/typeclass/NonEmptyTraversable"
import * as of from "@fp-ts/core/typeclass/Of"

@@ -42,5 +65,10 @@ import * as order from "@fp-ts/core/typeclass/Order"

import * as traversable from "@fp-ts/core/typeclass/Traversable"
import * as traversableFilterable from "@fp-ts/core/typeclass/TraversableFilterable"
export {
/**
* @since 1.0.0
*/
_function as function,
/**
* @category typeclass

@@ -61,2 +89,10 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
bigint,
/**
* @since 1.0.0
*/
boolean,
/**
* @category typeclass

@@ -75,2 +111,7 @@ * @since 1.0.0

*/
compactable,
/**
* @category typeclass
* @since 1.0.0
*/
contravariant,

@@ -88,5 +129,19 @@ /**

/**
* @since 1.0.0
*/
either,
/**
* @category typeclass
* @since 1.0.0
*/
equivalence,
/**
* @category typeclass
* @since 1.0.0
*/
filterable,
/**
* @category typeclass
* @since 1.0.0
*/
flatMap,

@@ -103,2 +158,6 @@ /**

/**
* @since 1.0.0
*/
identity,
/**
* @category typeclass

@@ -119,6 +178,5 @@ * @since 1.0.0

/**
* @category typeclass
* @since 1.0.0
*/
nonEmptyTraversable,
number,
/**

@@ -130,2 +188,6 @@ * @category typeclass

/**
* @since 1.0.0
*/
option,
/**
* @category typeclass

@@ -136,2 +198,6 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
ordering,
/**
* @category typeclass

@@ -142,2 +208,6 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
predicate,
/**
* @category typeclass

@@ -148,2 +218,10 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
readonlyArray,
/**
* @since 1.0.0
*/
readonlyRecord,
/**
* @category typeclass

@@ -174,6 +252,31 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
string,
/**
* @since 1.0.0
*/
struct,
/**
* @since 1.0.0
*/
symbol,
/**
* @since 1.0.0
*/
these,
/**
* @category typeclass
* @since 1.0.0
*/
traversable
traversable,
/**
* @category typeclass
* @since 1.0.0
*/
traversableFilterable,
/**
* @since 1.0.0
*/
tuple
}
/**
* @since 1.0.0
*/
import { identity } from "@fp-ts/core/Function"
import type { Kind, TypeClass, TypeLambda } from "@fp-ts/core/HKT"
import { identity } from "@fp-ts/core/internal/Function"
import type { Covariant } from "@fp-ts/core/typeclass/Covariant"

@@ -7,0 +7,0 @@

@@ -5,4 +5,7 @@ /**

import type { TypeLambda } from "@fp-ts/core/HKT"
import type { Monoid } from "@fp-ts/core/typeclass/Monoid"
import * as monoid from "@fp-ts/core/typeclass/Monoid"
import * as order from "@fp-ts/core/typeclass/Order"
import type { Order } from "@fp-ts/core/typeclass/Order"
import * as semigroup from "@fp-ts/core/typeclass/Semigroup"

@@ -27,2 +30,30 @@ /**

/**
* `Monoid` that returns last minimum of elements.
*
* @category constructors
* @since 1.0.0
*/
export const min = <A>(B: Bounded<A>): Monoid<A> =>
monoid.fromSemigroup(semigroup.min(B), B.maxBound)
/**
* `Monoid` that returns last maximum of elements.
*
* @category constructors
* @since 1.0.0
*/
export const max = <A>(B: Bounded<A>): Monoid<A> =>
monoid.fromSemigroup(semigroup.max(B), B.minBound)
/**
* @category instances
* @since 1.0.0
*/
export const number: Bounded<number> = {
compare: order.number.compare,
maxBound: Infinity,
minBound: -Infinity
}
/**
* Clamp a value between `minBound` and `maxBound` values.

@@ -29,0 +60,0 @@ *

/**
* @since 1.0.0
*/
import { pipe } from "@fp-ts/core/Function"
import type { Kind, TypeLambda } from "@fp-ts/core/HKT"
import { pipe } from "@fp-ts/core/internal/Function"
import type { Covariant } from "@fp-ts/core/typeclass/Covariant"

@@ -59,3 +59,3 @@ import type { FlatMap } from "@fp-ts/core/typeclass/FlatMap"

E1 | E2,
{ readonly [K in keyof A | N]: K extends keyof A ? A[K] : B }
{ [K in keyof A | N]: K extends keyof A ? A[K] : B }
> =>

@@ -62,0 +62,0 @@ F.flatMap(a =>

/**
* @since 1.0.0
*/
import { identity, pipe } from "@fp-ts/core/Function"
import type { Kind, TypeClass, TypeLambda } from "@fp-ts/core/HKT"
import { identity, pipe } from "@fp-ts/core/internal/Function"

@@ -7,0 +7,0 @@ /**

@@ -5,4 +5,4 @@ /**

import { identity, pipe } from "@fp-ts/core/Function"
import type { Kind, TypeClass, TypeLambda } from "@fp-ts/core/HKT"
import { identity, pipe } from "@fp-ts/core/internal/Function"
import type { Coproduct } from "@fp-ts/core/typeclass/Coproduct"

@@ -112,5 +112,2 @@ import type { Monad } from "@fp-ts/core/typeclass/Monad"

): <FR, FO, FE>(self: Kind<F, FR, FO, FE, A>) => Kind<G, R, O, E, B> =>
F.reduce<A, Kind<G, R, O, E, B>>(
G.zero(),
(gb, a) => pipe(gb, G.coproduct(f(a)))
)
F.reduce<A, Kind<G, R, O, E, B>>(G.zero(), (gb, a) => G.coproduct(gb, f(a)))

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

F: Invariant<F>
): (<R, O, E, A>(self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, readonly [A]>) =>
F.imap(a => [a] as const, ([a]) => a)
): (<R, O, E, A>(self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, [A]>) =>
F.imap(a => [a], ([a]) => a)

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

/**
* Optimised.
*
* @category constructors

@@ -27,3 +25,3 @@ * @since 1.0.0

empty,
combineAll: collection => S.combineMany(collection)(empty)
combineAll: collection => S.combineMany(empty, collection)
})

@@ -54,2 +52,3 @@

*
* @category combinators
* @since 1.0.0

@@ -60,6 +59,140 @@ */

/**
* Given a struct of monoids returns a monoid for the struct.
* @category instances
* @since 1.0.0
*/
export const string: Monoid<string> = {
...semigroup.string,
combineAll: (collection) => semigroup.string.combineMany("", collection),
empty: ""
}
/**
* `number` monoid under addition.
*
* The `empty` value is `0`.
*
* @category instances
* @since 1.0.0
*/
export const numberSum: Monoid<number> = {
...semigroup.numberSum,
combineAll: (collection) => semigroup.numberSum.combineMany(0, collection),
empty: 0
}
/**
* `number` monoid under multiplication.
*
* The `empty` value is `1`.
*
* @category instances
* @since 1.0.0
*/
export const numberMultiply: Monoid<number> = {
...semigroup.numberMultiply,
combineAll: (collection) => semigroup.numberMultiply.combineMany(1, collection),
empty: 1
}
/**
* `number` monoid under addition.
*
* The `bigint` value is `0n`.
*
* @category instances
* @since 1.0.0
*/
export const bigintSum: Monoid<bigint> = {
...semigroup.bigintSum,
combineAll: (collection) => semigroup.bigintSum.combineMany(0n, collection),
empty: 0n
}
/**
* `bigint` monoid under multiplication.
*
* The `empty` value is `1n`.
*
* @category instances
* @since 1.0.0
*/
export const bigintMultiply: Monoid<bigint> = {
...semigroup.bigintMultiply,
combineAll: (collection) => semigroup.bigintMultiply.combineMany(1n, collection),
empty: 1n
}
/**
* `boolean` monoid under conjunction.
*
* The `empty` value is `true`.
*
* @category instances
* @since 1.0.0
*/
export const booleanAll: Monoid<boolean> = {
...semigroup.booleanAll,
combineAll: (collection) => semigroup.booleanAll.combineMany(true, collection),
empty: true
}
/**
* `boolean` monoid under disjunction.
*
* The `empty` value is `false`.
*
* @category instances
* @since 1.0.0
*/
export const booleanAny: Monoid<boolean> = {
...semigroup.booleanAny,
combineAll: (collection) => semigroup.booleanAny.combineMany(false, collection),
empty: false
}
/**
* Given a tuple of `Monoid`s returns a `Monoid` for the tuple.
*
* @category combinators
* @since 1.0.0
*/
export const tuple = <A extends ReadonlyArray<any>>(
...monoids: { [K in keyof A]: Monoid<A[K]> }
): Monoid<A> => {
const empty: A = monoids.map((m) => m.empty) as any
return fromSemigroup(semigroup.tuple<A>(...monoids), empty)
}
/**
* Given a type `A`, this function creates and returns a `Monoid` for `Array<A>`.
* The returned `Monoid`'s empty value is the empty array.
*
* @category combinators
* @since 1.0.0
*/
export const array = <A>(): Monoid<Array<A>> => {
const S = semigroup.array<A>()
return ({
combine: S.combine,
combineMany: S.combineMany,
combineAll: (collection) => S.combineMany([], collection),
empty: []
})
}
/**
* Given a type `A`, this function creates and returns a `Semigroup` for `ReadonlyArray<A>`.
* The returned `Monoid`'s empty value is the empty array.
*
* @category combinators
* @since 1.0.0
*/
export const readonlyArray: <A>() => Monoid<ReadonlyArray<A>> = array as any
/**
* Given a struct of `Monoid`s returns a `Monoid` for the struct.
*
* @category combinators
* @since 1.0.0
*/
export const struct = <A>(

@@ -76,13 +209,1 @@ monoids: { readonly [K in keyof A]: Monoid<A[K]> }

}
/**
* Given a tuple of monoids returns a monoid for the tuple.
*
* @since 1.0.0
*/
export const tuple = <A extends ReadonlyArray<any>>(
...monoids: { [K in keyof A]: Monoid<A[K]> }
): Monoid<Readonly<A>> => {
const empty: A = monoids.map((m) => m.empty) as any
return fromSemigroup(semigroup.tuple(...monoids), empty)
}

@@ -18,3 +18,3 @@ /**

export interface Order<A> {
readonly compare: (that: A) => (self: A) => -1 | 0 | 1
readonly compare: (self: A, that: A) => -1 | 0 | 1
}

@@ -31,2 +31,34 @@

/**
* @category instances
* @since 1.0.0
*/
export const string: Order<string> = {
compare: (self, that) => self < that ? -1 : self > that ? 1 : 0
}
/**
* @category instances
* @since 1.0.0
*/
export const number: Order<number> = {
compare: (self, that) => self < that ? -1 : self > that ? 1 : 0
}
/**
* @category instances
* @since 1.0.0
*/
export const boolean: Order<boolean> = {
compare: (self, that) => self < that ? -1 : self > that ? 1 : 0
}
/**
* @category instances
* @since 1.0.0
*/
export const bigint: Order<bigint> = {
compare: (self, that) => self < that ? -1 : self > that ? 1 : 0
}
/**
* Main constructor.

@@ -38,31 +70,77 @@ *

export const fromCompare = <A>(compare: Order<A>["compare"]): Order<A> => ({
compare: that => self => self === that ? 0 : compare(that)(self)
compare: (self, that) => self === that ? 0 : compare(self, that)
})
/**
* Given a tuple of `Compare`s returns a `Compare` for the tuple.
* This function creates and returns a new `Order` for a tuple of values based on the given `Order`s for each element in the tuple.
* The returned `Order` compares two tuples of the same type by applying the corresponding `Order` to each element in the tuple.
* It is useful when you need to compare two tuples of the same type and you have a specific way of comparing each element
* of the tuple.
*
* @category combinators
* @since 1.0.0
*/
export const tuple = <A extends ReadonlyArray<any>>(
...orders: { [K in keyof A]: Order<A[K]> }
...orders: { readonly [K in keyof A]: Order<A[K]> }
): Order<Readonly<A>> =>
fromCompare(that =>
self => {
let i = 0
for (; i < orders.length - 1; i++) {
const r = orders[i].compare(that[i])(self[i])
if (r !== 0) {
return r
}
fromCompare((self, that) => {
let i = 0
for (; i < orders.length - 1; i++) {
const r = orders[i].compare(self[i], that[i])
if (r !== 0) {
return r
}
return orders[i].compare(that[i])(self[i])
}
)
return orders[i].compare(self[i], that[i])
})
/**
* This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.
* The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.
* If all elements are equal, the arrays are then compared based on their length.
* It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.
*
* @category combinators
* @since 1.0.0
*/
export const array = <A>(O: Order<A>): Order<ReadonlyArray<A>> =>
fromCompare((self, that) => {
const aLen = self.length
const bLen = that.length
const len = Math.min(aLen, bLen)
for (let i = 0; i < len; i++) {
const o = O.compare(self[i], that[i])
if (o !== 0) {
return o
}
}
return number.compare(aLen, bLen)
})
/**
* This function creates and returns a new `Order` for a struct of values based on the given `Order`s
* for each property in the struct.
*
* @category combinators
* @since 1.0.0
*/
export const struct = <A>(orders: { readonly [K in keyof A]: Order<A[K]> }): Order<
{ readonly [K in keyof A]: A[K] }
> => ({
compare: (self, that) => {
for (const key of Object.keys(orders)) {
const o = orders[key].compare(self[key], that[key])
if (o !== 0) {
return o
}
}
return 0
}
})
/**
* @since 1.0.0
*/
export const reverse = <A>(O: Order<A>): Order<A> =>
fromCompare(that => self => O.compare(self)(that))
fromCompare((self, that) => O.compare(that, self))

@@ -73,3 +151,3 @@ /**

export const contramap = <B, A>(f: (b: B) => A) =>
(self: Order<A>): Order<B> => fromCompare((b2) => (b1) => self.compare(f(b2))(f(b1)))
(self: Order<A>): Order<B> => fromCompare((b1, b2) => self.compare(f(b1), f(b2)))

@@ -81,33 +159,27 @@ /**

export const getSemigroup = <A>(): Semigroup<Order<A>> => ({
combine: (O2) =>
(O1) =>
fromCompare(that =>
self => {
const out = O1.compare(that)(self)
if (out !== 0) {
return out
}
return O2.compare(that)(self)
}
),
combineMany: (collection) =>
(self) =>
fromCompare(a2 =>
a1 => {
let out = self.compare(a2)(a1)
if (out !== 0) {
return out
}
for (const O of collection) {
out = O.compare(a2)(a1)
if (out !== 0) {
return out
}
}
combine: (O1, O2) =>
fromCompare((self, that) => {
const out = O1.compare(self, that)
if (out !== 0) {
return out
}
return O2.compare(self, that)
}),
combineMany: (self, collection) =>
fromCompare((a1, a2) => {
let out = self.compare(a1, a2)
if (out !== 0) {
return out
}
for (const O of collection) {
out = O.compare(a1, a2)
if (out !== 0) {
return out
}
)
}
return out
})
})
const empty: Order<unknown> = fromCompare(() => () => 0)
const empty: Order<unknown> = fromCompare(() => 0)

@@ -142,4 +214,4 @@ /**

imap: Contravariant.imap,
product: that => self => tuple(self, that),
productMany: collection => self => tuple(self, ...collection)
product: tuple,
productMany: (self, collection) => tuple(self, ...collection)
}

@@ -162,3 +234,3 @@

*/
export const lessThan = <A>(O: Order<A>) => (that: A) => (self: A) => O.compare(that)(self) === -1
export const lessThan = <A>(O: Order<A>) => (that: A) => (self: A) => O.compare(self, that) === -1

@@ -170,3 +242,3 @@ /**

*/
export const greaterThan = <A>(O: Order<A>) => (that: A) => (self: A) => O.compare(that)(self) === 1
export const greaterThan = <A>(O: Order<A>) => (that: A) => (self: A) => O.compare(self, that) === 1

@@ -179,3 +251,3 @@ /**

export const lessThanOrEqualTo = <A>(O: Order<A>) =>
(that: A) => (self: A) => O.compare(that)(self) !== 1
(that: A) => (self: A) => O.compare(self, that) !== 1

@@ -188,3 +260,3 @@ /**

export const greaterThanOrEqualTo = <A>(O: Order<A>) =>
(that: A) => (self: A) => O.compare(that)(self) !== -1
(that: A) => (self: A) => O.compare(self, that) !== -1

@@ -197,3 +269,3 @@ /**

export const min = <A>(O: Order<A>) =>
(that: A) => (self: A): A => self === that || O.compare(that)(self) < 1 ? self : that
(that: A) => (self: A): A => self === that || O.compare(self, that) < 1 ? self : that

@@ -206,3 +278,3 @@ /**

export const max = <A>(O: Order<A>) =>
(that: A) => (self: A): A => self === that || O.compare(that)(self) > -1 ? self : that
(that: A) => (self: A): A => self === that || O.compare(self, that) > -1 ? self : that

@@ -209,0 +281,0 @@ /**

/**
* @since 1.0.0
*/
import { pipe } from "@fp-ts/core/Function"
import type { Kind, TypeLambda } from "@fp-ts/core/HKT"
import { pipe } from "@fp-ts/core/internal/Function"
import type { Of } from "@fp-ts/core/typeclass/Of"

@@ -16,3 +16,3 @@ import type { SemiProduct } from "@fp-ts/core/typeclass/SemiProduct"

collection: Iterable<Kind<F, R, O, E, A>>
) => Kind<F, R, O, E, ReadonlyArray<A>>
) => Kind<F, R, O, E, Array<A>>
}

@@ -29,3 +29,3 @@

([T[number]] extends [Kind<F, any, any, infer E, any>] ? E : never),
Readonly<{ [I in keyof T]: [T[I]] extends [Kind<F, any, any, any, infer A>] ? A : never }>
{ [I in keyof T]: [T[I]] extends [Kind<F, any, any, any, infer A>] ? A : never }
> => F.productAll(components) as any

@@ -37,3 +37,3 @@

export const struct = <F extends TypeLambda>(F: Product<F>) =>
<R extends Record<string, Kind<F, any, any, any, any>>>(fields: R): Kind<
<R extends { readonly [x: string]: Kind<F, any, any, any, any> }>(fields: R): Kind<
F,

@@ -43,3 +43,3 @@ ([R[keyof R]] extends [Kind<F, infer R, any, any, any>] ? R : never),

([R[keyof R]] extends [Kind<F, any, any, infer E, any>] ? E : never),
{ readonly [K in keyof R]: [R[K]] extends [Kind<F, any, any, any, infer A>] ? A : never }
{ [K in keyof R]: [R[K]] extends [Kind<F, any, any, any, infer A>] ? A : never }
> => {

@@ -46,0 +46,0 @@ const keys = Object.keys(fields)

/**
* @since 1.0.0
*/
import { pipe } from "@fp-ts/core/Function"
import type { Kind, TypeLambda } from "@fp-ts/core/HKT"
import { pipe } from "@fp-ts/core/internal/Function"
import type { Covariant } from "@fp-ts/core/typeclass/Covariant"

@@ -23,10 +23,8 @@ import type { Semigroup } from "@fp-ts/core/typeclass/Semigroup"

<A, R, O, E>(S: Semigroup<A>): Semigroup<Kind<F, R, O, E, A>> => ({
combine: that => self => pipe(self, F.product(that), F.map(([a1, a2]) => S.combine(a2)(a1))),
combineMany: collection =>
self =>
pipe(
self,
F.productMany(collection),
F.map(([head, ...tail]) => pipe(head, S.combineMany(tail)))
)
combine: (self, that) => pipe(F.product(self, that), F.map(([a1, a2]) => S.combine(a1, a2))),
combineMany: (self, collection) =>
pipe(
F.productMany(self, collection),
F.map(([head, ...tail]) => S.combineMany(head, tail))
)
})

@@ -43,3 +41,3 @@

self: Kind<F, R1, O1, E1, (a: A) => B>
): Kind<F, R1 & R2, O1 | O2, E1 | E2, B> => pipe(self, F.product(fa), F.map(([f, a]) => f(a)))
): Kind<F, R1 & R2, O1 | O2, E1 | E2, B> => pipe(F.product(self, fa), F.map(([f, a]) => f(a)))

@@ -55,3 +53,3 @@ /**

self: Kind<F, R1, O1, E1, A>
): Kind<F, R1 & R2, O1 | O2, E1 | E2, A> => pipe(self, F.product(that), F.map(([a]) => a))
): Kind<F, R1 & R2, O1 | O2, E1 | E2, A> => pipe(F.product(self, that), F.map(([a]) => a))

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

self: Kind<F, R1, O1, E1, _>
): Kind<F, R1 & R2, O1 | O2, E1 | E2, B> => pipe(self, F.product(that), F.map(([_, a]) => a))
): Kind<F, R1 & R2, O1 | O2, E1 | E2, B> => pipe(F.product(self, that), F.map(([_, a]) => a))

@@ -80,3 +78,3 @@ /**

fb: Kind<F, R2, O2, E2, B>
): Kind<F, R1 & R2, O1 | O2, E1 | E2, C> => pipe(fa, F.product(fb), F.map(([a, b]) => f(a, b)))
): Kind<F, R1 & R2, O1 | O2, E1 | E2, C> => pipe(F.product(fa, fb), F.map(([a, b]) => f(a, b)))

@@ -96,6 +94,4 @@ /**

pipe(
fa,
F.product(fb),
F.product(fc),
F.product(F.product(fa, fb), fc),
F.map(([[a, b], c]) => f(a, b, c))
)
/**
* @since 1.0.0
*/
import type { Kind, TypeLambda } from "@fp-ts/core/HKT"

@@ -13,11 +14,11 @@ import type { Invariant } from "@fp-ts/core/typeclass/Invariant"

export interface SemiCoproduct<F extends TypeLambda> extends Invariant<F> {
readonly coproduct: <R2, O2, E2, B>(
readonly coproduct: <R1, O1, E1, A, R2, O2, E2, B>(
self: Kind<F, R1, O1, E1, A>,
that: Kind<F, R2, O2, E2, B>
) => <R1, O1, E1, A>(
self: Kind<F, R1, O1, E1, A>
) => Kind<F, R1 & R2, O1 | O2, E1 | E2, A | B>
readonly coproductMany: <R, O, E, A>(
self: Kind<F, R, O, E, A>,
collection: Iterable<Kind<F, R, O, E, A>>
) => (self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, A>
) => Kind<F, R, O, E, A>
}

@@ -29,7 +30,5 @@

export const getSemigroup = <F extends TypeLambda>(F: SemiCoproduct<F>) =>
<R, O, E, A>(): Semigroup<
Kind<F, R, O, E, A>
> => ({
<R, O, E, A>(): Semigroup<Kind<F, R, O, E, A>> => ({
combine: F.coproduct,
combineMany: F.coproductMany
})

@@ -6,4 +6,4 @@ /**

* export interface Semigroup<A> {
* combine: (that: A) => (self: A) => A
* combineMany: (collection: Iterable<A>) => (self: A) => A
* combine: (self: A, that: A) => A
* combineMany: (self: A, collection: Iterable<A>) => A
* }

@@ -25,3 +25,3 @@ * ```

import type { TypeLambda } from "@fp-ts/core/HKT"
import { identity } from "@fp-ts/core/internal/Function"
import { fromIterable } from "@fp-ts/core/internal/ReadonlyArray"
import type * as invariant from "@fp-ts/core/typeclass/Invariant"

@@ -37,4 +37,4 @@ import type { Order } from "@fp-ts/core/typeclass/Order"

export interface Semigroup<A> {
readonly combine: (that: A) => (self: A) => A
readonly combineMany: (collection: Iterable<A>) => (self: A) => A
readonly combine: (self: A, that: A) => A
readonly combineMany: (self: A, collection: Iterable<A>) => A
}

@@ -58,95 +58,221 @@

combine,
combineMany: (collection) =>
(self) => {
let out: A = self
for (const a of collection) {
out = combine(a)(out)
}
return out
combineMany: (self, collection) => {
let out: A = self
for (const a of collection) {
out = combine(out, a)
}
return out
}
})
/**
* `Semigroup` that returns last minimum of elements.
* @category instances
* @since 1.0.0
*/
export const string: Semigroup<string> = fromCombine((self, that) => self + that)
/**
* `number` semigroup under addition.
*
* @category constructors
* @category instances
* @since 1.0.0
*/
export const min = <A>(O: Order<A>): Semigroup<A> =>
fromCombine((that) => (self) => O.compare(that)(self) === -1 ? self : that)
export const numberSum: Semigroup<number> = fromCombine((self, that) => self + that)
/**
* `Semigroup` that returns last maximum of elements.
* `number` semigroup under multiplication.
*
* @category constructors
* @category instances
* @since 1.0.0
*/
export const max = <A>(O: Order<A>): Semigroup<A> =>
fromCombine((that) => (self) => O.compare(that)(self) === 1 ? self : that)
export const numberMultiply: Semigroup<number> = {
combine: (self, that) => self * that,
combineMany: (self, collection) => {
if (self === 0) {
return 0
}
let out = self
for (const n of collection) {
if (n === 0) {
return 0
}
out = out * n
}
return out
}
}
/**
* @category constructors
* `bigint` semigroup under addition.
*
* @category instances
* @since 1.0.0
*/
export const constant = <A>(a: A): Semigroup<A> => ({
combine: () => () => a,
combineMany: () => () => a
})
export const bigintSum: Semigroup<bigint> = fromCombine((self, that) => self + that)
/**
* The dual of a `Semigroup`, obtained by flipping the arguments of `combine`.
* `bigint` semigroup under multiplication.
*
* @category instances
* @since 1.0.0
*/
export const reverse = <A>(S: Semigroup<A>): Semigroup<A> => ({
combine: (that) => (self) => S.combine(self)(that),
combineMany: (collection) =>
(self) => {
const reversed = Array.from(collection).reverse()
return reversed.length > 0 ?
S.combine(self)(S.combineMany(reversed.slice(1))(reversed[0])) :
self
export const bigintMultiply: Semigroup<bigint> = {
combine: (self, that) => self * that,
combineMany: (self, collection) => {
if (self === 0n) {
return 0n
}
})
let out = self
for (const n of collection) {
if (n === 0n) {
return 0n
}
out = out * n
}
return out
}
}
/**
* Given a struct of associatives returns an associative for the struct.
* `boolean` semigroup under conjunction.
*
* @category instances
* @since 1.0.0
*/
export const struct = <A>(semigroups: { [K in keyof A]: Semigroup<A[K]> }): Semigroup<
{
readonly [K in keyof A]: A[K]
export const booleanAll: Semigroup<boolean> = {
combine: (self, that) => self && that,
combineMany: (self, collection) => {
if (self === false) {
return false
}
for (const b of collection) {
if (b === false) {
return false
}
}
return true
}
> =>
fromCombine((that) =>
(self) => {
const r = {} as any
for (const k in semigroups) {
if (Object.prototype.hasOwnProperty.call(semigroups, k)) {
r[k] = semigroups[k].combine(that[k])(self[k])
}
}
/**
* `boolean` semigroup under disjunction.
*
* @category instances
* @since 1.0.0
*/
export const booleanAny: Semigroup<boolean> = {
combine: (self, that) => self || that,
combineMany: (self, collection) => {
if (self === true) {
return true
}
for (const b of collection) {
if (b === true) {
return true
}
return r
}
)
return false
}
}
/**
* Given a tuple of associatives returns an associative for the tuple.
* This function creates and returns a new `Semigroup` for a tuple of values based on the given `Semigroup`s for each element in the tuple.
* The returned `Semigroup` combines two tuples of the same type by applying the corresponding `Semigroup` passed as arguments to each element in the tuple.
* It is useful when you need to combine two tuples of the same type and you have a specific way of combining each element of the tuple.
*
* @category combinators
* @since 1.0.0
*/
export const tuple = <A extends ReadonlyArray<any>>(
...semigroups: { [K in keyof A]: Semigroup<A[K]> }
): Semigroup<Readonly<A>> =>
fromCombine((that) => (self) => semigroups.map((S, i) => S.combine(that[i])(self[i])) as any)
...semigroups: { readonly [K in keyof A]: Semigroup<A[K]> }
): Semigroup<A> =>
fromCombine((self, that) => semigroups.map((S, i) => S.combine(self[i], that[i])) as any)
/**
* Given a type `A`, this function creates and returns a `Semigroup` for `Array<A>`.
* The returned `Semigroup` combines two arrays by concatenating them.
*
* @category combinators
* @since 1.0.0
*/
export const array = <A>(): Semigroup<Array<A>> => fromCombine((self, that) => self.concat(that))
/**
* Given a type `A`, this function creates and returns a `Semigroup` for `ReadonlyArray<A>`.
* The returned `Semigroup` combines two arrays by concatenating them.
*
* @category combinators
* @since 1.0.0
*/
export const readonlyArray: <A>() => Semigroup<ReadonlyArray<A>> = array as any
/**
* This function creates and returns a new `Semigroup` for a struct of values based on the given `Semigroup`s for each property in the struct.
* The returned `Semigroup` combines two structs of the same type by applying the corresponding `Semigroup` passed as arguments to each property in the struct.
* It is useful when you need to combine two structs of the same type and you have a specific way of combining each property of the struct.
*
* @category combinators
* @since 1.0.0
*/
export const struct = <A>(semigroups: { readonly [K in keyof A]: Semigroup<A[K]> }): Semigroup<
{ readonly [K in keyof A]: A[K] }
> =>
fromCombine((self, that) => {
const r = {} as any
for (const k in semigroups) {
if (Object.prototype.hasOwnProperty.call(semigroups, k)) {
r[k] = semigroups[k].combine(self[k], that[k])
}
}
return r
})
/**
* `Semigroup` that returns last minimum of elements.
*
* @category constructors
* @since 1.0.0
*/
export const min = <A>(O: Order<A>): Semigroup<A> =>
fromCombine((self, that) => O.compare(self, that) === -1 ? self : that)
/**
* `Semigroup` that returns last maximum of elements.
*
* @category constructors
* @since 1.0.0
*/
export const max = <A>(O: Order<A>): Semigroup<A> =>
fromCombine((self, that) => O.compare(self, that) === 1 ? self : that)
/**
* @category constructors
* @since 1.0.0
*/
export const constant = <A>(a: A): Semigroup<A> => ({
combine: () => a,
combineMany: () => a
})
/**
* The dual of a `Semigroup`, obtained by flipping the arguments of `combine`.
*
* @since 1.0.0
*/
export const reverse = <A>(S: Semigroup<A>): Semigroup<A> => ({
combine: (self, that) => S.combine(that, self),
combineMany: (self, collection) => {
const reversed = Array.from(collection).reverse()
return reversed.length > 0 ?
S.combine(S.combineMany(reversed[0], reversed.slice(1)), self) :
self
}
})
/**
* @since 1.0.0
*/
export const intercalate = <A>(separator: A) =>
(S: Semigroup<A>): Semigroup<A> =>
fromCombine(
(that) => S.combineMany([separator, that])
)
fromCombine((self, that) => S.combineMany(self, [separator, that]))

@@ -160,4 +286,4 @@ /**

export const first = <A = never>(): Semigroup<A> => ({
combine: () => identity,
combineMany: () => identity
combine: (a) => a,
combineMany: (a) => a
})

@@ -172,10 +298,9 @@

export const last = <A = never>(): Semigroup<A> => ({
combine: second => () => second,
combineMany: collection =>
self => {
let a: A = self
// eslint-disable-next-line no-empty
for (a of collection) {}
return a
}
combine: (_, second) => second,
combineMany: (self, collection) => {
let a: A = self
// eslint-disable-next-line no-empty
for (a of collection) {}
return a
}
})

@@ -191,10 +316,5 @@

(S: Semigroup<A>): Semigroup<B> => ({
combine: that => self => to(S.combine(from(that))(from(self))),
combineMany: (collection) =>
self =>
to(
S.combineMany(
(Array.isArray(collection) ? collection : Array.from(collection)).map(from)
)(from(self))
)
combine: (self, that) => to(S.combine(from(self), from(that))),
combineMany: (self, collection) =>
to(S.combineMany(from(self), (fromIterable(collection)).map(from)))
})

@@ -216,4 +336,4 @@

...Invariant,
product: that => self => tuple(self, that),
productMany: collection => self => tuple(self, ...collection)
product: tuple,
productMany: (self, collection) => tuple(self, ...collection)
}

@@ -220,0 +340,0 @@

/**
* @since 1.0.0
*/
import { pipe } from "@fp-ts/core/Function"
import type { Kind, TypeLambda } from "@fp-ts/core/HKT"
import { pipe } from "@fp-ts/core/internal/Function"
import type { Covariant } from "@fp-ts/core/typeclass/Covariant"

@@ -15,11 +15,11 @@ import type { Invariant } from "@fp-ts/core/typeclass/Invariant"

export interface SemiProduct<F extends TypeLambda> extends Invariant<F> {
readonly product: <R2, O2, E2, B>(
readonly product: <R1, O1, E1, A, R2, O2, E2, B>(
self: Kind<F, R1, O1, E1, A>,
that: Kind<F, R2, O2, E2, B>
) => <R1, O1, E1, A>(
self: Kind<F, R1, O1, E1, A>
) => Kind<F, R1 & R2, O1 | O2, E1 | E2, readonly [A, B]>
) => Kind<F, R1 & R2, O1 | O2, E1 | E2, [A, B]>
readonly productMany: <R, O, E, A>(
self: Kind<F, R, O, E, A>,
collection: Iterable<Kind<F, R, O, E, A>>
) => (self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, readonly [A, ...Array<A>]>
) => Kind<F, R, O, E, [A, ...Array<A>]>
}

@@ -36,14 +36,12 @@

) =>
<FR2, FO2, FE2, GR2, GO2, GE2, B>(
<FR1, FO1, FE1, GR1, GO1, GE1, A, FR2, FO2, FE2, GR2, GO2, GE2, B>(
self: Kind<F, FR1, FO1, FE1, Kind<G, GR1, GO1, GE1, A>>,
that: Kind<F, FR2, FO2, FE2, Kind<G, GR2, GO2, GE2, B>>
) =>
<FR1, FO1, FE1, GR1, GO1, GE1, A>(
self: Kind<F, FR1, FO1, FE1, Kind<G, GR1, GO1, GE1, A>>
): Kind<
F,
FR1 & FR2,
FO1 | FO2,
FE1 | FE2,
Kind<G, GR1 & GR2, GO1 | GO2, GE1 | GE2, readonly [A, B]>
> => pipe(self, F.product(that), F.map(([ga, gb]) => pipe(ga, G.product(gb))))
): Kind<
F,
FR1 & FR2,
FO1 | FO2,
FE1 | FE2,
Kind<G, GR1 & GR2, GO1 | GO2, GE1 | GE2, [A, B]>
> => pipe(F.product(self, that), F.map(([ga, gb]) => G.product(ga, gb)))

@@ -60,12 +58,9 @@ /**

<FR, FO, FE, GR, GO, GE, A>(
self: Kind<F, FR, FO, FE, Kind<G, GR, GO, GE, A>>,
collection: Iterable<Kind<F, FR, FO, FE, Kind<G, GR, GO, GE, A>>>
) =>
(
self: Kind<F, FR, FO, FE, Kind<G, GR, GO, GE, A>>
): Kind<F, FR, FO, FE, Kind<G, GR, GO, GE, readonly [A, ...Array<A>]>> =>
pipe(
self,
F.productMany(collection),
F.map(([ga, ...gas]) => pipe(ga, G.productMany(gas)))
)
): Kind<F, FR, FO, FE, Kind<G, GR, GO, GE, [A, ...Array<A>]>> =>
pipe(
F.productMany(self, collection),
F.map(([ga, ...gas]) => G.productMany(ga, gas))
)

@@ -83,18 +78,17 @@ /**

<R, O, E, A>(
self: Kind<F, R, O, E, A>,
collection: Iterable<Kind<F, R, O, E, A>>
) =>
(self: Kind<F, R, O, E, A>) => {
let out = pipe(
self,
Covariant.map((a): readonly [A, ...Array<A>] => [a])
) => {
let out = pipe(
self,
Covariant.map((a): [A, ...Array<A>] => [a])
)
for (const fa of collection) {
out = pipe(
product(out, fa),
Covariant.map(([[head, ...tail], a]): [A, ...Array<A>] => [head, ...tail, a])
)
for (const fa of collection) {
out = pipe(
out,
product(fa),
Covariant.map(([[head, ...tail], a]): readonly [A, ...Array<A>] => [head, ...tail, a])
)
}
return out
}
return out
}

@@ -116,7 +110,6 @@ /**

E1 | E2,
{ readonly [K in keyof A | N]: K extends keyof A ? A[K] : B }
{ [K in keyof A | N]: K extends keyof A ? A[K] : B }
> =>
pipe(
self,
F.product(that),
F.product(self, that),
F.imap(

@@ -129,5 +122,7 @@ ([a, b]) => Object.assign({}, a, { [name]: b }) as any,

/**
* Adds an element to the end of a tuple.
*
* @since 1.0.0
*/
export const productFlatten = <F extends TypeLambda>(F: SemiProduct<F>) =>
export const element = <F extends TypeLambda>(F: SemiProduct<F>) =>
<R2, O2, E2, B>(

@@ -138,7 +133,6 @@ that: Kind<F, R2, O2, E2, B>

self: Kind<F, R1, O1, E1, A>
): Kind<F, R1 & R2, O1 | O2, E1 | E2, readonly [...A, B]> =>
): Kind<F, R1 & R2, O1 | O2, E1 | E2, [...A, B]> =>
pipe(
self,
F.product(that),
F.imap(([a, b]) => [...a, b] as const, ab => [ab.slice(0, -1), ab[ab.length - 1]] as any)
F.product(self, that),
F.imap(([a, b]) => [...a, b], ab => [ab.slice(0, -1), ab[ab.length - 1]] as any)
)

@@ -157,4 +151,4 @@

([T[number]] extends [Kind<F, any, any, infer E, any>] ? E : never),
Readonly<{ [I in keyof T]: [T[I]] extends [Kind<F, any, any, any, infer A>] ? A : never }>
> => F.productMany(components.slice(1))(components[0]) as any
{ [I in keyof T]: [T[I]] extends [Kind<F, any, any, any, infer A>] ? A : never }
> => F.productMany(components[0], components.slice(1)) as any

@@ -167,4 +161,4 @@ type EnforceNonEmptyRecord<R> = keyof R extends never ? never : R

export const nonEmptyStruct = <F extends TypeLambda>(F: SemiProduct<F>) =>
<R extends Readonly<Record<string, Kind<F, any, any, any, any>>>>(
fields: EnforceNonEmptyRecord<R> & Record<string, Kind<F, any, any, any, any>>
<R extends { readonly [x: string]: Kind<F, any, any, any, any> }>(
fields: EnforceNonEmptyRecord<R> & { readonly [x: string]: Kind<F, any, any, any, any> }
): Kind<

@@ -175,7 +169,7 @@ F,

([R[keyof R]] extends [Kind<F, any, any, infer E, any>] ? E : never),
{ readonly [K in keyof R]: [R[K]] extends [Kind<F, any, any, any, infer A>] ? A : never }
{ [K in keyof R]: [R[K]] extends [Kind<F, any, any, any, infer A>] ? A : never }
> => {
const keys = Object.keys(fields)
return pipe(
F.productMany(keys.slice(1).map(k => fields[k]))(fields[keys[0]]),
F.productMany(fields[keys[0]], keys.slice(1).map(k => fields[k])),
F.imap(([value, ...values]) => {

@@ -182,0 +176,0 @@ const out: any = { [keys[0]]: value }

/**
* @since 1.0.0
*/
import { identity, pipe } from "@fp-ts/core/Function"
import type { Kind, TypeClass, TypeLambda } from "@fp-ts/core/HKT"
import { identity, pipe } from "@fp-ts/core/internal/Function"
import type { Applicative } from "@fp-ts/core/typeclass/Applicative"

@@ -7,0 +7,0 @@ import type { Covariant } from "@fp-ts/core/typeclass/Covariant"

@@ -1,4 +0,1 @@

/**
* @since 1.0.0
*/
import type { Kind, TypeClass, TypeLambda } from "@fp-ts/core/HKT";

@@ -5,0 +2,0 @@ import type { Covariant } from "@fp-ts/core/typeclass/Covariant";

@@ -7,4 +7,8 @@ "use strict";

exports.mapLeft = exports.map = exports.bimapComposition = void 0;
var _Function = /*#__PURE__*/require("@fp-ts/core/internal/Function");
var _Function = /*#__PURE__*/require("@fp-ts/core/Function");
/**
* @since 1.0.0
*/
/**
* Returns a default `bimap` composition.

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

@@ -5,2 +5,3 @@ /**

import type { TypeLambda } from "@fp-ts/core/HKT";
import type { Monoid } from "@fp-ts/core/typeclass/Monoid";
import type { Order } from "@fp-ts/core/typeclass/Order";

@@ -23,2 +24,21 @@ /**

/**
* `Monoid` that returns last minimum of elements.
*
* @category constructors
* @since 1.0.0
*/
export declare const min: <A>(B: Bounded<A>) => Monoid<A>;
/**
* `Monoid` that returns last maximum of elements.
*
* @category constructors
* @since 1.0.0
*/
export declare const max: <A>(B: Bounded<A>) => Monoid<A>;
/**
* @category instances
* @since 1.0.0
*/
export declare const number: Bounded<number>;
/**
* Clamp a value between `minBound` and `maxBound` values.

@@ -25,0 +45,0 @@ *

@@ -6,7 +6,34 @@ "use strict";

});
exports.reverse = exports.clamp = void 0;
exports.reverse = exports.number = exports.min = exports.max = exports.clamp = void 0;
var monoid = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/Monoid"));
var order = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/Order"));
var semigroup = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/Semigroup"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**
* `Monoid` that returns last minimum of elements.
*
* @category constructors
* @since 1.0.0
*/
const min = B => monoid.fromSemigroup(semigroup.min(B), B.maxBound);
/**
* `Monoid` that returns last maximum of elements.
*
* @category constructors
* @since 1.0.0
*/
exports.min = min;
const max = B => monoid.fromSemigroup(semigroup.max(B), B.minBound);
/**
* @category instances
* @since 1.0.0
*/
exports.max = max;
const number = {
compare: order.number.compare,
maxBound: Infinity,
minBound: -Infinity
};
/**
* Clamp a value between `minBound` and `maxBound` values.

@@ -16,2 +43,3 @@ *

*/
exports.number = number;
const clamp = B => order.clamp(B)(B.minBound, B.maxBound);

@@ -18,0 +46,0 @@ /**

@@ -1,4 +0,1 @@

/**
* @since 1.0.0
*/
import type { Kind, TypeLambda } from "@fp-ts/core/HKT";

@@ -30,3 +27,3 @@ import type { Covariant } from "@fp-ts/core/typeclass/Covariant";

*/
export declare const bind: <F extends TypeLambda>(F: Chainable<F>) => <N extends string, A extends object, R2, O2, E2, B>(name: Exclude<N, keyof A>, f: (a: A) => Kind<F, R2, O2, E2, B>) => <R1, O1, E1>(self: Kind<F, R1, O1, E1, A>) => Kind<F, R1 & R2, O2 | O1, E2 | E1, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B; }>;
export declare const bind: <F extends TypeLambda>(F: Chainable<F>) => <N extends string, A extends object, R2, O2, E2, B>(name: Exclude<N, keyof A>, f: (a: A) => Kind<F, R2, O2, E2, B>) => <R1, O1, E1>(self: Kind<F, R1, O1, E1, A>) => Kind<F, R1 & R2, O2 | O1, E2 | E1, { [K in N | keyof A]: K extends keyof A ? A[K] : B; }>;
//# sourceMappingURL=Chainable.d.ts.map

@@ -7,4 +7,8 @@ "use strict";

exports.tap = exports.bind = exports.andThenDiscard = void 0;
var _Function = /*#__PURE__*/require("@fp-ts/core/internal/Function");
var _Function = /*#__PURE__*/require("@fp-ts/core/Function");
/**
* @since 1.0.0
*/
/**
* Returns an effect that effectfully "peeks" at the success of this effect.

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

@@ -1,4 +0,1 @@

/**
* @since 1.0.0
*/
import type { Kind, TypeClass, TypeLambda } from "@fp-ts/core/HKT";

@@ -5,0 +2,0 @@ /**

@@ -7,6 +7,10 @@ "use strict";

exports.flatten = exports.composeKleisliArrow = exports.andThen = void 0;
var _Function = /*#__PURE__*/require("@fp-ts/core/internal/Function");
var _Function = /*#__PURE__*/require("@fp-ts/core/Function");
/**
* @since 1.0.0
*/
/**
* @since 1.0.0
*/
const flatten = F => self => (0, _Function.pipe)(self, F.flatMap(_Function.identity));

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

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

exports.toArrayWith = exports.toArray = exports.reduceRightKind = exports.reduceRight = exports.reduceKind = exports.reduceComposition = exports.foldMapKind = exports.foldMap = void 0;
var _Function = /*#__PURE__*/require("@fp-ts/core/internal/Function");
var _Function = /*#__PURE__*/require("@fp-ts/core/Function");
/**

@@ -56,4 +56,4 @@ * @since 1.0.0

exports.reduceRightKind = reduceRightKind;
const foldMapKind = F => G => f => F.reduce(G.zero(), (gb, a) => (0, _Function.pipe)(gb, G.coproduct(f(a))));
const foldMapKind = F => G => f => F.reduce(G.zero(), (gb, a) => G.coproduct(gb, f(a)));
exports.foldMapKind = foldMapKind;
//# sourceMappingURL=Foldable.js.map

@@ -25,3 +25,3 @@ /**

*/
export declare const tupled: <F extends TypeLambda>(F: Invariant<F>) => <R, O, E, A>(self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, readonly [A]>;
export declare const tupled: <F extends TypeLambda>(F: Invariant<F>) => <R, O, E, A>(self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, [A]>;
//# sourceMappingURL=Invariant.d.ts.map

@@ -15,4 +15,2 @@ /**

/**
* Optimised.
*
* @category constructors

@@ -43,2 +41,3 @@ * @since 1.0.0

*
* @category combinators
* @since 1.0.0

@@ -48,13 +47,90 @@ */

/**
* Given a struct of monoids returns a monoid for the struct.
* @category instances
* @since 1.0.0
*/
export declare const string: Monoid<string>;
/**
* `number` monoid under addition.
*
* The `empty` value is `0`.
*
* @category instances
* @since 1.0.0
*/
export declare const struct: <A>(monoids: { readonly [K in keyof A]: Monoid<A[K]>; }) => Monoid<{ readonly [K_1 in keyof A]: A[K_1]; }>;
export declare const numberSum: Monoid<number>;
/**
* Given a tuple of monoids returns a monoid for the tuple.
* `number` monoid under multiplication.
*
* The `empty` value is `1`.
*
* @category instances
* @since 1.0.0
*/
export declare const tuple: <A extends readonly any[]>(...monoids: { [K in keyof A]: Monoid<A[K]>; }) => Monoid<Readonly<A>>;
export declare const numberMultiply: Monoid<number>;
/**
* `number` monoid under addition.
*
* The `bigint` value is `0n`.
*
* @category instances
* @since 1.0.0
*/
export declare const bigintSum: Monoid<bigint>;
/**
* `bigint` monoid under multiplication.
*
* The `empty` value is `1n`.
*
* @category instances
* @since 1.0.0
*/
export declare const bigintMultiply: Monoid<bigint>;
/**
* `boolean` monoid under conjunction.
*
* The `empty` value is `true`.
*
* @category instances
* @since 1.0.0
*/
export declare const booleanAll: Monoid<boolean>;
/**
* `boolean` monoid under disjunction.
*
* The `empty` value is `false`.
*
* @category instances
* @since 1.0.0
*/
export declare const booleanAny: Monoid<boolean>;
/**
* Given a tuple of `Monoid`s returns a `Monoid` for the tuple.
*
* @category combinators
* @since 1.0.0
*/
export declare const tuple: <A extends readonly any[]>(...monoids: { [K in keyof A]: Monoid<A[K]>; }) => Monoid<A>;
/**
* Given a type `A`, this function creates and returns a `Monoid` for `Array<A>`.
* The returned `Monoid`'s empty value is the empty array.
*
* @category combinators
* @since 1.0.0
*/
export declare const array: <A>() => Monoid<A[]>;
/**
* Given a type `A`, this function creates and returns a `Semigroup` for `ReadonlyArray<A>`.
* The returned `Monoid`'s empty value is the empty array.
*
* @category combinators
* @since 1.0.0
*/
export declare const readonlyArray: <A>() => Monoid<ReadonlyArray<A>>;
/**
* Given a struct of `Monoid`s returns a `Monoid` for the struct.
*
* @category combinators
* @since 1.0.0
*/
export declare const struct: <A>(monoids: { readonly [K in keyof A]: Monoid<A[K]>; }) => Monoid<{ readonly [K_1 in keyof A]: A[K_1]; }>;
//# sourceMappingURL=Monoid.d.ts.map

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

});
exports.tuple = exports.struct = exports.reverse = exports.min = exports.max = exports.fromSemigroup = void 0;
exports.tuple = exports.struct = exports.string = exports.reverse = exports.readonlyArray = exports.numberSum = exports.numberMultiply = exports.min = exports.max = exports.fromSemigroup = exports.booleanAny = exports.booleanAll = exports.bigintSum = exports.bigintMultiply = exports.array = void 0;
var semigroup = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/Semigroup"));

@@ -12,4 +12,2 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

/**
* Optimised.
*
* @category constructors

@@ -21,3 +19,3 @@ * @since 1.0.0

empty,
combineAll: collection => S.combineMany(collection)(empty)
combineAll: collection => S.combineMany(empty, collection)
});

@@ -47,2 +45,3 @@ /**

*
* @category combinators
* @since 1.0.0

@@ -53,7 +52,139 @@ */

/**
* Given a struct of monoids returns a monoid for the struct.
* @category instances
* @since 1.0.0
*/
exports.reverse = reverse;
const string = {
...semigroup.string,
combineAll: collection => semigroup.string.combineMany("", collection),
empty: ""
};
/**
* `number` monoid under addition.
*
* The `empty` value is `0`.
*
* @category instances
* @since 1.0.0
*/
exports.reverse = reverse;
exports.string = string;
const numberSum = {
...semigroup.numberSum,
combineAll: collection => semigroup.numberSum.combineMany(0, collection),
empty: 0
};
/**
* `number` monoid under multiplication.
*
* The `empty` value is `1`.
*
* @category instances
* @since 1.0.0
*/
exports.numberSum = numberSum;
const numberMultiply = {
...semigroup.numberMultiply,
combineAll: collection => semigroup.numberMultiply.combineMany(1, collection),
empty: 1
};
/**
* `number` monoid under addition.
*
* The `bigint` value is `0n`.
*
* @category instances
* @since 1.0.0
*/
exports.numberMultiply = numberMultiply;
const bigintSum = {
...semigroup.bigintSum,
combineAll: collection => semigroup.bigintSum.combineMany(0n, collection),
empty: 0n
};
/**
* `bigint` monoid under multiplication.
*
* The `empty` value is `1n`.
*
* @category instances
* @since 1.0.0
*/
exports.bigintSum = bigintSum;
const bigintMultiply = {
...semigroup.bigintMultiply,
combineAll: collection => semigroup.bigintMultiply.combineMany(1n, collection),
empty: 1n
};
/**
* `boolean` monoid under conjunction.
*
* The `empty` value is `true`.
*
* @category instances
* @since 1.0.0
*/
exports.bigintMultiply = bigintMultiply;
const booleanAll = {
...semigroup.booleanAll,
combineAll: collection => semigroup.booleanAll.combineMany(true, collection),
empty: true
};
/**
* `boolean` monoid under disjunction.
*
* The `empty` value is `false`.
*
* @category instances
* @since 1.0.0
*/
exports.booleanAll = booleanAll;
const booleanAny = {
...semigroup.booleanAny,
combineAll: collection => semigroup.booleanAny.combineMany(false, collection),
empty: false
};
/**
* Given a tuple of `Monoid`s returns a `Monoid` for the tuple.
*
* @category combinators
* @since 1.0.0
*/
exports.booleanAny = booleanAny;
const tuple = (...monoids) => {
const empty = monoids.map(m => m.empty);
return fromSemigroup(semigroup.tuple(...monoids), empty);
};
/**
* Given a type `A`, this function creates and returns a `Monoid` for `Array<A>`.
* The returned `Monoid`'s empty value is the empty array.
*
* @category combinators
* @since 1.0.0
*/
exports.tuple = tuple;
const array = () => {
const S = semigroup.array();
return {
combine: S.combine,
combineMany: S.combineMany,
combineAll: collection => S.combineMany([], collection),
empty: []
};
};
/**
* Given a type `A`, this function creates and returns a `Semigroup` for `ReadonlyArray<A>`.
* The returned `Monoid`'s empty value is the empty array.
*
* @category combinators
* @since 1.0.0
*/
exports.array = array;
const readonlyArray = array;
/**
* Given a struct of `Monoid`s returns a `Monoid` for the struct.
*
* @category combinators
* @since 1.0.0
*/
exports.readonlyArray = readonlyArray;
const struct = monoids => {

@@ -68,13 +199,3 @@ const empty = {};

};
/**
* Given a tuple of monoids returns a monoid for the tuple.
*
* @since 1.0.0
*/
exports.struct = struct;
const tuple = (...monoids) => {
const empty = monoids.map(m => m.empty);
return fromSemigroup(semigroup.tuple(...monoids), empty);
};
exports.tuple = tuple;
//# sourceMappingURL=Monoid.js.map

@@ -16,3 +16,3 @@ /**

export interface Order<A> {
readonly compare: (that: A) => (self: A) => -1 | 0 | 1;
readonly compare: (self: A, that: A) => -1 | 0 | 1;
}

@@ -27,2 +27,22 @@ /**

/**
* @category instances
* @since 1.0.0
*/
export declare const string: Order<string>;
/**
* @category instances
* @since 1.0.0
*/
export declare const number: Order<number>;
/**
* @category instances
* @since 1.0.0
*/
export declare const boolean: Order<boolean>;
/**
* @category instances
* @since 1.0.0
*/
export declare const bigint: Order<bigint>;
/**
* Main constructor.

@@ -33,12 +53,34 @@ *

*/
export declare const fromCompare: <A>(compare: (that: A) => (self: A) => -1 | 0 | 1) => Order<A>;
export declare const fromCompare: <A>(compare: (self: A, that: A) => -1 | 0 | 1) => Order<A>;
/**
* Given a tuple of `Compare`s returns a `Compare` for the tuple.
* This function creates and returns a new `Order` for a tuple of values based on the given `Order`s for each element in the tuple.
* The returned `Order` compares two tuples of the same type by applying the corresponding `Order` to each element in the tuple.
* It is useful when you need to compare two tuples of the same type and you have a specific way of comparing each element
* of the tuple.
*
* @category combinators
* @since 1.0.0
*/
export declare const tuple: <A extends readonly any[]>(...orders: { [K in keyof A]: Order<A[K]>; }) => Order<Readonly<A>>;
export declare const tuple: <A extends readonly any[]>(...orders: { readonly [K in keyof A]: Order<A[K]>; }) => Order<Readonly<A>>;
/**
* This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.
* The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.
* If all elements are equal, the arrays are then compared based on their length.
* It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.
*
* @category combinators
* @since 1.0.0
*/
export declare const array: <A>(O: Order<A>) => Order<readonly A[]>;
/**
* This function creates and returns a new `Order` for a struct of values based on the given `Order`s
* for each property in the struct.
*
* @category combinators
* @since 1.0.0
*/
export declare const struct: <A>(orders: { readonly [K in keyof A]: Order<A[K]>; }) => Order<{ readonly [K_1 in keyof A]: A[K_1]; }>;
/**
* @since 1.0.0
*/
export declare const reverse: <A>(O: Order<A>) => Order<A>;

@@ -45,0 +87,0 @@ /**

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

});
exports.tuple = exports.reverse = exports.min = exports.max = exports.lessThanOrEqualTo = exports.lessThan = exports.greaterThanOrEqualTo = exports.greaterThan = exports.getSemigroup = exports.getMonoid = exports.fromCompare = exports.contramap = exports.clamp = exports.between = exports.SemiProduct = exports.Product = exports.Invariant = exports.Contravariant = void 0;
exports.tuple = exports.struct = exports.string = exports.reverse = exports.number = exports.min = exports.max = exports.lessThanOrEqualTo = exports.lessThan = exports.greaterThanOrEqualTo = exports.greaterThan = exports.getSemigroup = exports.getMonoid = exports.fromCompare = exports.contramap = exports.clamp = exports.boolean = exports.bigint = exports.between = exports.array = exports.SemiProduct = exports.Product = exports.Invariant = exports.Contravariant = void 0;
var contravariant = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/Contravariant"));

@@ -13,2 +13,33 @@ var monoid = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/core/typeclass/Monoid"));

/**
* @category instances
* @since 1.0.0
*/
const string = {
compare: (self, that) => self < that ? -1 : self > that ? 1 : 0
};
/**
* @category instances
* @since 1.0.0
*/
exports.string = string;
const number = {
compare: (self, that) => self < that ? -1 : self > that ? 1 : 0
};
/**
* @category instances
* @since 1.0.0
*/
exports.number = number;
const boolean = {
compare: (self, that) => self < that ? -1 : self > that ? 1 : 0
};
/**
* @category instances
* @since 1.0.0
*/
exports.boolean = boolean;
const bigint = {
compare: (self, that) => self < that ? -1 : self > that ? 1 : 0
};
/**
* Main constructor.

@@ -19,15 +50,20 @@ *

*/
exports.bigint = bigint;
const fromCompare = compare => ({
compare: that => self => self === that ? 0 : compare(that)(self)
compare: (self, that) => self === that ? 0 : compare(self, that)
});
/**
* Given a tuple of `Compare`s returns a `Compare` for the tuple.
* This function creates and returns a new `Order` for a tuple of values based on the given `Order`s for each element in the tuple.
* The returned `Order` compares two tuples of the same type by applying the corresponding `Order` to each element in the tuple.
* It is useful when you need to compare two tuples of the same type and you have a specific way of comparing each element
* of the tuple.
*
* @category combinators
* @since 1.0.0
*/
exports.fromCompare = fromCompare;
const tuple = (...orders) => fromCompare(that => self => {
const tuple = (...orders) => fromCompare((self, that) => {
let i = 0;
for (; i < orders.length - 1; i++) {
const r = orders[i].compare(that[i])(self[i]);
const r = orders[i].compare(self[i], that[i]);
if (r !== 0) {

@@ -37,14 +73,55 @@ return r;

}
return orders[i].compare(that[i])(self[i]);
return orders[i].compare(self[i], that[i]);
});
/**
* This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.
* The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.
* If all elements are equal, the arrays are then compared based on their length.
* It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.
*
* @category combinators
* @since 1.0.0
*/
exports.tuple = tuple;
const reverse = O => fromCompare(that => self => O.compare(self)(that));
const array = O => fromCompare((self, that) => {
const aLen = self.length;
const bLen = that.length;
const len = Math.min(aLen, bLen);
for (let i = 0; i < len; i++) {
const o = O.compare(self[i], that[i]);
if (o !== 0) {
return o;
}
}
return number.compare(aLen, bLen);
});
/**
* This function creates and returns a new `Order` for a struct of values based on the given `Order`s
* for each property in the struct.
*
* @category combinators
* @since 1.0.0
*/
exports.array = array;
const struct = orders => ({
compare: (self, that) => {
for (const key of Object.keys(orders)) {
const o = orders[key].compare(self[key], that[key]);
if (o !== 0) {
return o;
}
}
return 0;
}
});
/**
* @since 1.0.0
*/
exports.struct = struct;
const reverse = O => fromCompare((self, that) => O.compare(that, self));
/**
* @since 1.0.0
*/
exports.reverse = reverse;
const contramap = f => self => fromCompare(b2 => b1 => self.compare(f(b2))(f(b1)));
const contramap = f => self => fromCompare((b1, b2) => self.compare(f(b1), f(b2)));
/**

@@ -56,11 +133,11 @@ * @category instances

const getSemigroup = () => ({
combine: O2 => O1 => fromCompare(that => self => {
const out = O1.compare(that)(self);
combine: (O1, O2) => fromCompare((self, that) => {
const out = O1.compare(self, that);
if (out !== 0) {
return out;
}
return O2.compare(that)(self);
return O2.compare(self, that);
}),
combineMany: collection => self => fromCompare(a2 => a1 => {
let out = self.compare(a2)(a1);
combineMany: (self, collection) => fromCompare((a1, a2) => {
let out = self.compare(a1, a2);
if (out !== 0) {

@@ -70,3 +147,3 @@ return out;

for (const O of collection) {
out = O.compare(a2)(a1);
out = O.compare(a1, a2);
if (out !== 0) {

@@ -80,3 +157,3 @@ return out;

exports.getSemigroup = getSemigroup;
const empty = /*#__PURE__*/fromCompare(() => () => 0);
const empty = /*#__PURE__*/fromCompare(() => 0);
/**

@@ -108,4 +185,4 @@ * @category instances

imap: Contravariant.imap,
product: that => self => tuple(self, that),
productMany: collection => self => tuple(self, ...collection)
product: tuple,
productMany: (self, collection) => tuple(self, ...collection)
};

@@ -128,3 +205,3 @@ /**

exports.Product = Product;
const lessThan = O => that => self => O.compare(that)(self) === -1;
const lessThan = O => that => self => O.compare(self, that) === -1;
/**

@@ -136,3 +213,3 @@ * Test whether one value is _strictly greater than_ another.

exports.lessThan = lessThan;
const greaterThan = O => that => self => O.compare(that)(self) === 1;
const greaterThan = O => that => self => O.compare(self, that) === 1;
/**

@@ -144,3 +221,3 @@ * Test whether one value is _non-strictly less than_ another.

exports.greaterThan = greaterThan;
const lessThanOrEqualTo = O => that => self => O.compare(that)(self) !== 1;
const lessThanOrEqualTo = O => that => self => O.compare(self, that) !== 1;
/**

@@ -152,3 +229,3 @@ * Test whether one value is _non-strictly greater than_ another.

exports.lessThanOrEqualTo = lessThanOrEqualTo;
const greaterThanOrEqualTo = O => that => self => O.compare(that)(self) !== -1;
const greaterThanOrEqualTo = O => that => self => O.compare(self, that) !== -1;
/**

@@ -160,3 +237,3 @@ * Take the minimum of two values. If they are considered equal, the first argument is chosen.

exports.greaterThanOrEqualTo = greaterThanOrEqualTo;
const min = O => that => self => self === that || O.compare(that)(self) < 1 ? self : that;
const min = O => that => self => self === that || O.compare(self, that) < 1 ? self : that;
/**

@@ -168,3 +245,3 @@ * Take the maximum of two values. If they are considered equal, the first argument is chosen.

exports.min = min;
const max = O => that => self => self === that || O.compare(that)(self) > -1 ? self : that;
const max = O => that => self => self === that || O.compare(self, that) > -1 ? self : that;
/**

@@ -171,0 +248,0 @@ * Clamp a value between a minimum and a maximum.

@@ -1,4 +0,1 @@

/**
* @since 1.0.0
*/
import type { Kind, TypeLambda } from "@fp-ts/core/HKT";

@@ -12,3 +9,3 @@ import type { Of } from "@fp-ts/core/typeclass/Of";

export interface Product<F extends TypeLambda> extends SemiProduct<F>, Of<F> {
readonly productAll: <R, O, E, A>(collection: Iterable<Kind<F, R, O, E, A>>) => Kind<F, R, O, E, ReadonlyArray<A>>;
readonly productAll: <R, O, E, A>(collection: Iterable<Kind<F, R, O, E, A>>) => Kind<F, R, O, E, Array<A>>;
}

@@ -18,7 +15,9 @@ /**

*/
export declare const tuple: <F extends TypeLambda>(F: Product<F>) => <T extends readonly Kind<F, any, any, any, any>[]>(...components: T) => Kind<F, [T[number]] extends [Kind<F, infer R, any, any, any>] ? R : never, [T[number]] extends [Kind<F, any, infer O, any, any>] ? O : never, [T[number]] extends [Kind<F, any, any, infer E, any>] ? E : never, Readonly<{ [I in keyof T]: [T[I]] extends [Kind<F, any, any, any, infer A>] ? A : never; }>>;
export declare const tuple: <F extends TypeLambda>(F: Product<F>) => <T extends readonly Kind<F, any, any, any, any>[]>(...components: T) => Kind<F, [T[number]] extends [Kind<F, infer R, any, any, any>] ? R : never, [T[number]] extends [Kind<F, any, infer O, any, any>] ? O : never, [T[number]] extends [Kind<F, any, any, infer E, any>] ? E : never, { [I in keyof T]: [T[I]] extends [Kind<F, any, any, any, infer A>] ? A : never; }>;
/**
* @since 1.0.0
*/
export declare const struct: <F extends TypeLambda>(F: Product<F>) => <R extends Record<string, Kind<F, any, any, any, any>>>(fields: R) => Kind<F, [R[keyof R]] extends [Kind<F, infer R_1, any, any, any>] ? R_1 : never, [R[keyof R]] extends [Kind<F, any, infer O, any, any>] ? O : never, [R[keyof R]] extends [Kind<F, any, any, infer E, any>] ? E : never, { readonly [K in keyof R]: [R[K]] extends [Kind<F, any, any, any, infer A>] ? A : never; }>;
export declare const struct: <F extends TypeLambda>(F: Product<F>) => <R extends {
readonly [x: string]: Kind<F, any, any, any, any>;
}>(fields: R) => Kind<F, [R[keyof R]] extends [Kind<F, infer R_1, any, any, any>] ? R_1 : never, [R[keyof R]] extends [Kind<F, any, infer O, any, any>] ? O : never, [R[keyof R]] extends [Kind<F, any, any, infer E, any>] ? E : never, { [K in keyof R]: [R[K]] extends [Kind<F, any, any, any, infer A>] ? A : never; }>;
//# sourceMappingURL=Product.d.ts.map

@@ -7,6 +7,10 @@ "use strict";

exports.tuple = exports.struct = void 0;
var _Function = /*#__PURE__*/require("@fp-ts/core/internal/Function");
var _Function = /*#__PURE__*/require("@fp-ts/core/Function");
/**
* @since 1.0.0
*/
/**
* @since 1.0.0
*/
const tuple = F => (...components) => F.productAll(components);

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

@@ -1,4 +0,1 @@

/**
* @since 1.0.0
*/
import type { Kind, TypeLambda } from "@fp-ts/core/HKT";

@@ -5,0 +2,0 @@ import type { Covariant } from "@fp-ts/core/typeclass/Covariant";

@@ -7,4 +7,8 @@ "use strict";

exports.liftSemigroup = exports.lift3 = exports.lift2 = exports.ap = exports.andThenDiscard = exports.andThen = void 0;
var _Function = /*#__PURE__*/require("@fp-ts/core/internal/Function");
var _Function = /*#__PURE__*/require("@fp-ts/core/Function");
/**
* @since 1.0.0
*/
/**
* Lift a `Semigroup` into 'F', the inner values are combined using the provided `Semigroup`.

@@ -15,4 +19,4 @@ *

const liftSemigroup = F => S => ({
combine: that => self => (0, _Function.pipe)(self, F.product(that), F.map(([a1, a2]) => S.combine(a2)(a1))),
combineMany: collection => self => (0, _Function.pipe)(self, F.productMany(collection), F.map(([head, ...tail]) => (0, _Function.pipe)(head, S.combineMany(tail))))
combine: (self, that) => (0, _Function.pipe)(F.product(self, that), F.map(([a1, a2]) => S.combine(a1, a2))),
combineMany: (self, collection) => (0, _Function.pipe)(F.productMany(self, collection), F.map(([head, ...tail]) => S.combineMany(head, tail)))
});

@@ -23,3 +27,3 @@ /**

exports.liftSemigroup = liftSemigroup;
const ap = F => fa => self => (0, _Function.pipe)(self, F.product(fa), F.map(([f, a]) => f(a)));
const ap = F => fa => self => (0, _Function.pipe)(F.product(self, fa), F.map(([f, a]) => f(a)));
/**

@@ -29,3 +33,3 @@ * @since 1.0.0

exports.ap = ap;
const andThenDiscard = F => that => self => (0, _Function.pipe)(self, F.product(that), F.map(([a]) => a));
const andThenDiscard = F => that => self => (0, _Function.pipe)(F.product(self, that), F.map(([a]) => a));
/**

@@ -35,3 +39,3 @@ * @since 1.0.0

exports.andThenDiscard = andThenDiscard;
const andThen = F => that => self => (0, _Function.pipe)(self, F.product(that), F.map(([_, a]) => a));
const andThen = F => that => self => (0, _Function.pipe)(F.product(self, that), F.map(([_, a]) => a));
/**

@@ -43,3 +47,3 @@ * Lifts a binary function into `F`.

exports.andThen = andThen;
const lift2 = F => f => (fa, fb) => (0, _Function.pipe)(fa, F.product(fb), F.map(([a, b]) => f(a, b)));
const lift2 = F => f => (fa, fb) => (0, _Function.pipe)(F.product(fa, fb), F.map(([a, b]) => f(a, b)));
/**

@@ -51,4 +55,4 @@ * Lifts a ternary function into 'F'.

exports.lift2 = lift2;
const lift3 = F => f => (fa, fb, fc) => (0, _Function.pipe)(fa, F.product(fb), F.product(fc), F.map(([[a, b], c]) => f(a, b, c)));
const lift3 = F => f => (fa, fb, fc) => (0, _Function.pipe)(F.product(F.product(fa, fb), fc), F.map(([[a, b], c]) => f(a, b, c)));
exports.lift3 = lift3;
//# sourceMappingURL=SemiApplicative.js.map

@@ -12,4 +12,4 @@ /**

export interface SemiCoproduct<F extends TypeLambda> extends Invariant<F> {
readonly coproduct: <R2, O2, E2, B>(that: Kind<F, R2, O2, E2, B>) => <R1, O1, E1, A>(self: Kind<F, R1, O1, E1, A>) => Kind<F, R1 & R2, O1 | O2, E1 | E2, A | B>;
readonly coproductMany: <R, O, E, A>(collection: Iterable<Kind<F, R, O, E, A>>) => (self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, A>;
readonly coproduct: <R1, O1, E1, A, R2, O2, E2, B>(self: Kind<F, R1, O1, E1, A>, that: Kind<F, R2, O2, E2, B>) => Kind<F, R1 & R2, O1 | O2, E1 | E2, A | B>;
readonly coproductMany: <R, O, E, A>(self: Kind<F, R, O, E, A>, collection: Iterable<Kind<F, R, O, E, A>>) => Kind<F, R, O, E, A>;
}

@@ -16,0 +16,0 @@ /**

@@ -10,2 +10,5 @@ "use strict";

*/
/**
* @since 1.0.0
*/
const getSemigroup = F => () => ({

@@ -12,0 +15,0 @@ combine: F.coproduct,

@@ -6,4 +6,4 @@ /**

* export interface Semigroup<A> {
* combine: (that: A) => (self: A) => A
* combineMany: (collection: Iterable<A>) => (self: A) => A
* combine: (self: A, that: A) => A
* combineMany: (self: A, collection: Iterable<A>) => A
* }

@@ -34,4 +34,4 @@ * ```

export interface Semigroup<A> {
readonly combine: (that: A) => (self: A) => A;
readonly combineMany: (collection: Iterable<A>) => (self: A) => A;
readonly combine: (self: A, that: A) => A;
readonly combineMany: (self: A, collection: Iterable<A>) => A;
}

@@ -51,4 +51,85 @@ /**

*/
export declare const fromCombine: <A>(combine: (that: A) => (self: A) => A) => Semigroup<A>;
export declare const fromCombine: <A>(combine: (self: A, that: A) => A) => Semigroup<A>;
/**
* @category instances
* @since 1.0.0
*/
export declare const string: Semigroup<string>;
/**
* `number` semigroup under addition.
*
* @category instances
* @since 1.0.0
*/
export declare const numberSum: Semigroup<number>;
/**
* `number` semigroup under multiplication.
*
* @category instances
* @since 1.0.0
*/
export declare const numberMultiply: Semigroup<number>;
/**
* `bigint` semigroup under addition.
*
* @category instances
* @since 1.0.0
*/
export declare const bigintSum: Semigroup<bigint>;
/**
* `bigint` semigroup under multiplication.
*
* @category instances
* @since 1.0.0
*/
export declare const bigintMultiply: Semigroup<bigint>;
/**
* `boolean` semigroup under conjunction.
*
* @category instances
* @since 1.0.0
*/
export declare const booleanAll: Semigroup<boolean>;
/**
* `boolean` semigroup under disjunction.
*
* @category instances
* @since 1.0.0
*/
export declare const booleanAny: Semigroup<boolean>;
/**
* This function creates and returns a new `Semigroup` for a tuple of values based on the given `Semigroup`s for each element in the tuple.
* The returned `Semigroup` combines two tuples of the same type by applying the corresponding `Semigroup` passed as arguments to each element in the tuple.
* It is useful when you need to combine two tuples of the same type and you have a specific way of combining each element of the tuple.
*
* @category combinators
* @since 1.0.0
*/
export declare const tuple: <A extends readonly any[]>(...semigroups: { readonly [K in keyof A]: Semigroup<A[K]>; }) => Semigroup<A>;
/**
* Given a type `A`, this function creates and returns a `Semigroup` for `Array<A>`.
* The returned `Semigroup` combines two arrays by concatenating them.
*
* @category combinators
* @since 1.0.0
*/
export declare const array: <A>() => Semigroup<A[]>;
/**
* Given a type `A`, this function creates and returns a `Semigroup` for `ReadonlyArray<A>`.
* The returned `Semigroup` combines two arrays by concatenating them.
*
* @category combinators
* @since 1.0.0
*/
export declare const readonlyArray: <A>() => Semigroup<ReadonlyArray<A>>;
/**
* This function creates and returns a new `Semigroup` for a struct of values based on the given `Semigroup`s for each property in the struct.
* The returned `Semigroup` combines two structs of the same type by applying the corresponding `Semigroup` passed as arguments to each property in the struct.
* It is useful when you need to combine two structs of the same type and you have a specific way of combining each property of the struct.
*
* @category combinators
* @since 1.0.0
*/
export declare const struct: <A>(semigroups: { readonly [K in keyof A]: Semigroup<A[K]>; }) => Semigroup<{ readonly [K_1 in keyof A]: A[K_1]; }>;
/**
* `Semigroup` that returns last minimum of elements.

@@ -79,16 +160,4 @@ *

/**
* Given a struct of associatives returns an associative for the struct.
*
* @since 1.0.0
*/
export declare const struct: <A>(semigroups: { [K in keyof A]: Semigroup<A[K]>; }) => Semigroup<{ readonly [K_1 in keyof A]: A[K_1]; }>;
/**
* Given a tuple of associatives returns an associative for the tuple.
*
* @since 1.0.0
*/
export declare const tuple: <A extends readonly any[]>(...semigroups: { [K in keyof A]: Semigroup<A[K]>; }) => Semigroup<Readonly<A>>;
/**
* @since 1.0.0
*/
export declare const intercalate: <A>(separator: A) => (S: Semigroup<A>) => Semigroup<A>;

@@ -95,0 +164,0 @@ /**

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

});
exports.tuple = exports.struct = exports.reverse = exports.min = exports.max = exports.last = exports.intercalate = exports.imap = exports.fromCombine = exports.first = exports.constant = exports.SemiProduct = exports.Product = exports.Invariant = void 0;
var _Function = /*#__PURE__*/require("@fp-ts/core/internal/Function");
exports.tuple = exports.struct = exports.string = exports.reverse = exports.readonlyArray = exports.numberSum = exports.numberMultiply = exports.min = exports.max = exports.last = exports.intercalate = exports.imap = exports.fromCombine = exports.first = exports.constant = exports.booleanAny = exports.booleanAll = exports.bigintSum = exports.bigintMultiply = exports.array = exports.SemiProduct = exports.Product = exports.Invariant = void 0;
var _ReadonlyArray = /*#__PURE__*/require("@fp-ts/core/internal/ReadonlyArray");
/**

@@ -17,6 +17,6 @@ * Useful when `combineMany` can't be optimised.

combine,
combineMany: collection => self => {
combineMany: (self, collection) => {
let out = self;
for (const a of collection) {
out = combine(a)(out);
out = combine(out, a);
}

@@ -27,50 +27,153 @@ return out;

/**
* `Semigroup` that returns last minimum of elements.
*
* @category constructors
* @category instances
* @since 1.0.0
*/
exports.fromCombine = fromCombine;
const min = O => fromCombine(that => self => O.compare(that)(self) === -1 ? self : that);
const string = /*#__PURE__*/fromCombine((self, that) => self + that);
/**
* `Semigroup` that returns last maximum of elements.
* `number` semigroup under addition.
*
* @category constructors
* @category instances
* @since 1.0.0
*/
exports.min = min;
const max = O => fromCombine(that => self => O.compare(that)(self) === 1 ? self : that);
exports.string = string;
const numberSum = /*#__PURE__*/fromCombine((self, that) => self + that);
/**
* @category constructors
* `number` semigroup under multiplication.
*
* @category instances
* @since 1.0.0
*/
exports.max = max;
const constant = a => ({
combine: () => () => a,
combineMany: () => () => a
});
exports.numberSum = numberSum;
const numberMultiply = {
combine: (self, that) => self * that,
combineMany: (self, collection) => {
if (self === 0) {
return 0;
}
let out = self;
for (const n of collection) {
if (n === 0) {
return 0;
}
out = out * n;
}
return out;
}
};
/**
* The dual of a `Semigroup`, obtained by flipping the arguments of `combine`.
* `bigint` semigroup under addition.
*
* @category instances
* @since 1.0.0
*/
exports.constant = constant;
const reverse = S => ({
combine: that => self => S.combine(self)(that),
combineMany: collection => self => {
const reversed = Array.from(collection).reverse();
return reversed.length > 0 ? S.combine(self)(S.combineMany(reversed.slice(1))(reversed[0])) : self;
exports.numberMultiply = numberMultiply;
const bigintSum = /*#__PURE__*/fromCombine((self, that) => self + that);
/**
* `bigint` semigroup under multiplication.
*
* @category instances
* @since 1.0.0
*/
exports.bigintSum = bigintSum;
const bigintMultiply = {
combine: (self, that) => self * that,
combineMany: (self, collection) => {
if (self === 0n) {
return 0n;
}
let out = self;
for (const n of collection) {
if (n === 0n) {
return 0n;
}
out = out * n;
}
return out;
}
});
};
/**
* Given a struct of associatives returns an associative for the struct.
* `boolean` semigroup under conjunction.
*
* @category instances
* @since 1.0.0
*/
exports.reverse = reverse;
const struct = semigroups => fromCombine(that => self => {
exports.bigintMultiply = bigintMultiply;
const booleanAll = {
combine: (self, that) => self && that,
combineMany: (self, collection) => {
if (self === false) {
return false;
}
for (const b of collection) {
if (b === false) {
return false;
}
}
return true;
}
};
/**
* `boolean` semigroup under disjunction.
*
* @category instances
* @since 1.0.0
*/
exports.booleanAll = booleanAll;
const booleanAny = {
combine: (self, that) => self || that,
combineMany: (self, collection) => {
if (self === true) {
return true;
}
for (const b of collection) {
if (b === true) {
return true;
}
}
return false;
}
};
/**
* This function creates and returns a new `Semigroup` for a tuple of values based on the given `Semigroup`s for each element in the tuple.
* The returned `Semigroup` combines two tuples of the same type by applying the corresponding `Semigroup` passed as arguments to each element in the tuple.
* It is useful when you need to combine two tuples of the same type and you have a specific way of combining each element of the tuple.
*
* @category combinators
* @since 1.0.0
*/
exports.booleanAny = booleanAny;
const tuple = (...semigroups) => fromCombine((self, that) => semigroups.map((S, i) => S.combine(self[i], that[i])));
/**
* Given a type `A`, this function creates and returns a `Semigroup` for `Array<A>`.
* The returned `Semigroup` combines two arrays by concatenating them.
*
* @category combinators
* @since 1.0.0
*/
exports.tuple = tuple;
const array = () => fromCombine((self, that) => self.concat(that));
/**
* Given a type `A`, this function creates and returns a `Semigroup` for `ReadonlyArray<A>`.
* The returned `Semigroup` combines two arrays by concatenating them.
*
* @category combinators
* @since 1.0.0
*/
exports.array = array;
const readonlyArray = array;
/**
* This function creates and returns a new `Semigroup` for a struct of values based on the given `Semigroup`s for each property in the struct.
* The returned `Semigroup` combines two structs of the same type by applying the corresponding `Semigroup` passed as arguments to each property in the struct.
* It is useful when you need to combine two structs of the same type and you have a specific way of combining each property of the struct.
*
* @category combinators
* @since 1.0.0
*/
exports.readonlyArray = readonlyArray;
const struct = semigroups => fromCombine((self, that) => {
const r = {};
for (const k in semigroups) {
if (Object.prototype.hasOwnProperty.call(semigroups, k)) {
r[k] = semigroups[k].combine(that[k])(self[k]);
r[k] = semigroups[k].combine(self[k], that[k]);
}

@@ -81,14 +184,45 @@ }

/**
* Given a tuple of associatives returns an associative for the tuple.
* `Semigroup` that returns last minimum of elements.
*
* @category constructors
* @since 1.0.0
*/
exports.struct = struct;
const tuple = (...semigroups) => fromCombine(that => self => semigroups.map((S, i) => S.combine(that[i])(self[i])));
const min = O => fromCombine((self, that) => O.compare(self, that) === -1 ? self : that);
/**
* `Semigroup` that returns last maximum of elements.
*
* @category constructors
* @since 1.0.0
*/
exports.tuple = tuple;
const intercalate = separator => S => fromCombine(that => S.combineMany([separator, that]));
exports.min = min;
const max = O => fromCombine((self, that) => O.compare(self, that) === 1 ? self : that);
/**
* @category constructors
* @since 1.0.0
*/
exports.max = max;
const constant = a => ({
combine: () => a,
combineMany: () => a
});
/**
* The dual of a `Semigroup`, obtained by flipping the arguments of `combine`.
*
* @since 1.0.0
*/
exports.constant = constant;
const reverse = S => ({
combine: (self, that) => S.combine(that, self),
combineMany: (self, collection) => {
const reversed = Array.from(collection).reverse();
return reversed.length > 0 ? S.combine(S.combineMany(reversed[0], reversed.slice(1)), self) : self;
}
});
/**
* @since 1.0.0
*/
exports.reverse = reverse;
const intercalate = separator => S => fromCombine((self, that) => S.combineMany(self, [separator, that]));
/**
* Always return the first argument.

@@ -101,4 +235,4 @@ *

const first = () => ({
combine: () => _Function.identity,
combineMany: () => _Function.identity
combine: a => a,
combineMany: a => a
});

@@ -113,4 +247,4 @@ /**

const last = () => ({
combine: second => () => second,
combineMany: collection => self => {
combine: (_, second) => second,
combineMany: (self, collection) => {
let a = self;

@@ -127,4 +261,4 @@ // eslint-disable-next-line no-empty

const imap = (to, from) => S => ({
combine: that => self => to(S.combine(from(that))(from(self))),
combineMany: collection => self => to(S.combineMany((Array.isArray(collection) ? collection : Array.from(collection)).map(from))(from(self)))
combine: (self, that) => to(S.combine(from(self), from(that))),
combineMany: (self, collection) => to(S.combineMany(from(self), (0, _ReadonlyArray.fromIterable)(collection).map(from)))
});

@@ -146,4 +280,4 @@ /**

...Invariant,
product: that => self => tuple(self, that),
productMany: collection => self => tuple(self, ...collection)
product: tuple,
productMany: (self, collection) => tuple(self, ...collection)
};

@@ -150,0 +284,0 @@ /**

@@ -1,4 +0,1 @@

/**
* @since 1.0.0
*/
import type { Kind, TypeLambda } from "@fp-ts/core/HKT";

@@ -13,4 +10,4 @@ import type { Covariant } from "@fp-ts/core/typeclass/Covariant";

export interface SemiProduct<F extends TypeLambda> extends Invariant<F> {
readonly product: <R2, O2, E2, B>(that: Kind<F, R2, O2, E2, B>) => <R1, O1, E1, A>(self: Kind<F, R1, O1, E1, A>) => Kind<F, R1 & R2, O1 | O2, E1 | E2, readonly [A, B]>;
readonly productMany: <R, O, E, A>(collection: Iterable<Kind<F, R, O, E, A>>) => (self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, readonly [A, ...Array<A>]>;
readonly product: <R1, O1, E1, A, R2, O2, E2, B>(self: Kind<F, R1, O1, E1, A>, that: Kind<F, R2, O2, E2, B>) => Kind<F, R1 & R2, O1 | O2, E1 | E2, [A, B]>;
readonly productMany: <R, O, E, A>(self: Kind<F, R, O, E, A>, collection: Iterable<Kind<F, R, O, E, A>>) => Kind<F, R, O, E, [A, ...Array<A>]>;
}

@@ -22,3 +19,3 @@ /**

*/
export declare const productComposition: <F extends TypeLambda, G extends TypeLambda>(F: SemiApplicative<F>, G: SemiProduct<G>) => <FR2, FO2, FE2, GR2, GO2, GE2, B>(that: Kind<F, FR2, FO2, FE2, Kind<G, GR2, GO2, GE2, B>>) => <FR1, FO1, FE1, GR1, GO1, GE1, A>(self: Kind<F, FR1, FO1, FE1, Kind<G, GR1, GO1, GE1, A>>) => Kind<F, FR1 & FR2, FO2 | FO1, FE2 | FE1, Kind<G, GR1 & GR2, GO2 | GO1, GE2 | GE1, readonly [A, B]>>;
export declare const productComposition: <F extends TypeLambda, G extends TypeLambda>(F: SemiApplicative<F>, G: SemiProduct<G>) => <FR1, FO1, FE1, GR1, GO1, GE1, A, FR2, FO2, FE2, GR2, GO2, GE2, B>(self: Kind<F, FR1, FO1, FE1, Kind<G, GR1, GO1, GE1, A>>, that: Kind<F, FR2, FO2, FE2, Kind<G, GR2, GO2, GE2, B>>) => Kind<F, FR1 & FR2, FO1 | FO2, FE1 | FE2, Kind<G, GR1 & GR2, GO1 | GO2, GE1 | GE2, [A, B]>>;
/**

@@ -29,3 +26,3 @@ * Returns a default `productMany` composition.

*/
export declare const productManyComposition: <F extends TypeLambda, G extends TypeLambda>(F: SemiApplicative<F>, G: SemiProduct<G>) => <FR, FO, FE, GR, GO, GE, A>(collection: Iterable<Kind<F, FR, FO, FE, Kind<G, GR, GO, GE, A>>>) => (self: Kind<F, FR, FO, FE, Kind<G, GR, GO, GE, A>>) => Kind<F, FR, FO, FE, Kind<G, GR, GO, GE, readonly [A, ...A[]]>>;
export declare const productManyComposition: <F extends TypeLambda, G extends TypeLambda>(F: SemiApplicative<F>, G: SemiProduct<G>) => <FR, FO, FE, GR, GO, GE, A>(self: Kind<F, FR, FO, FE, Kind<G, GR, GO, GE, A>>, collection: Iterable<Kind<F, FR, FO, FE, Kind<G, GR, GO, GE, A>>>) => Kind<F, FR, FO, FE, Kind<G, GR, GO, GE, [A, ...A[]]>>;
/**

@@ -37,15 +34,17 @@ * Returns a default `productMany` implementation (useful for tests).

*/
export declare const productMany: <F extends TypeLambda>(Covariant: Covariant<F>, product: <R2, O2, E2, B>(that: Kind<F, R2, O2, E2, B>) => <R1, O1, E1, A>(self: Kind<F, R1, O1, E1, A>) => Kind<F, R1 & R2, O2 | O1, E2 | E1, readonly [A, B]>) => <R, O, E, A_1>(collection: Iterable<Kind<F, R, O, E, A_1>>) => (self: Kind<F, R, O, E, A_1>) => Kind<F, R, O, E, readonly [A_1, ...A_1[]]>;
export declare const productMany: <F extends TypeLambda>(Covariant: Covariant<F>, product: <R1, O1, E1, A, R2, O2, E2, B>(self: Kind<F, R1, O1, E1, A>, that: Kind<F, R2, O2, E2, B>) => Kind<F, R1 & R2, O1 | O2, E1 | E2, [A, B]>) => <R, O, E, A_1>(self: Kind<F, R, O, E, A_1>, collection: Iterable<Kind<F, R, O, E, A_1>>) => Kind<F, R, O, E, [A_1, ...A_1[]]>;
/**
* @since 1.0.0
*/
export declare const andThenBind: <F extends TypeLambda>(F: SemiProduct<F>) => <N extends string, A extends object, R2, O2, E2, B>(name: Exclude<N, keyof A>, that: Kind<F, R2, O2, E2, B>) => <R1, O1, E1>(self: Kind<F, R1, O1, E1, A>) => Kind<F, R1 & R2, O2 | O1, E2 | E1, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B; }>;
export declare const andThenBind: <F extends TypeLambda>(F: SemiProduct<F>) => <N extends string, A extends object, R2, O2, E2, B>(name: Exclude<N, keyof A>, that: Kind<F, R2, O2, E2, B>) => <R1, O1, E1>(self: Kind<F, R1, O1, E1, A>) => Kind<F, R1 & R2, O2 | O1, E2 | E1, { [K in N | keyof A]: K extends keyof A ? A[K] : B; }>;
/**
* Adds an element to the end of a tuple.
*
* @since 1.0.0
*/
export declare const productFlatten: <F extends TypeLambda>(F: SemiProduct<F>) => <R2, O2, E2, B>(that: Kind<F, R2, O2, E2, B>) => <R1, O1, E1, A extends readonly any[]>(self: Kind<F, R1, O1, E1, A>) => Kind<F, R1 & R2, O2 | O1, E2 | E1, readonly [...A, B]>;
export declare const element: <F extends TypeLambda>(F: SemiProduct<F>) => <R2, O2, E2, B>(that: Kind<F, R2, O2, E2, B>) => <R1, O1, E1, A extends readonly any[]>(self: Kind<F, R1, O1, E1, A>) => Kind<F, R1 & R2, O2 | O1, E2 | E1, [...A, B]>;
/**
* @since 1.0.0
*/
export declare const nonEmptyTuple: <F extends TypeLambda>(F: SemiProduct<F>) => <T extends readonly [Kind<F, any, any, any, any>, ...Kind<F, any, any, any, any>[]]>(...components: T) => Kind<F, [T[number]] extends [Kind<F, infer R, any, any, any>] ? R : never, [T[number]] extends [Kind<F, any, infer O, any, any>] ? O : never, [T[number]] extends [Kind<F, any, any, infer E, any>] ? E : never, Readonly<{ [I in keyof T]: [T[I]] extends [Kind<F, any, any, any, infer A>] ? A : never; }>>;
export declare const nonEmptyTuple: <F extends TypeLambda>(F: SemiProduct<F>) => <T extends readonly [Kind<F, any, any, any, any>, ...Kind<F, any, any, any, any>[]]>(...components: T) => Kind<F, [T[number]] extends [Kind<F, infer R, any, any, any>] ? R : never, [T[number]] extends [Kind<F, any, infer O, any, any>] ? O : never, [T[number]] extends [Kind<F, any, any, infer E, any>] ? E : never, { [I in keyof T]: [T[I]] extends [Kind<F, any, any, any, infer A>] ? A : never; }>;
type EnforceNonEmptyRecord<R> = keyof R extends never ? never : R;

@@ -55,4 +54,8 @@ /**

*/
export declare const nonEmptyStruct: <F extends TypeLambda>(F: SemiProduct<F>) => <R extends Readonly<Record<string, Kind<F, any, any, any, any>>>>(fields: EnforceNonEmptyRecord<R> & Record<string, Kind<F, any, any, any, any>>) => Kind<F, [R[keyof R]] extends [Kind<F, infer R_1, any, any, any>] ? R_1 : never, [R[keyof R]] extends [Kind<F, any, infer O, any, any>] ? O : never, [R[keyof R]] extends [Kind<F, any, any, infer E, any>] ? E : never, { readonly [K in keyof R]: [R[K]] extends [Kind<F, any, any, any, infer A>] ? A : never; }>;
export declare const nonEmptyStruct: <F extends TypeLambda>(F: SemiProduct<F>) => <R extends {
readonly [x: string]: Kind<F, any, any, any, any>;
}>(fields: EnforceNonEmptyRecord<R> & {
readonly [x: string]: Kind<F, any, any, any, any>;
}) => Kind<F, [R[keyof R]] extends [Kind<F, infer R_1, any, any, any>] ? R_1 : never, [R[keyof R]] extends [Kind<F, any, infer O, any, any>] ? O : never, [R[keyof R]] extends [Kind<F, any, any, infer E, any>] ? E : never, { [K in keyof R]: [R[K]] extends [Kind<F, any, any, any, infer A>] ? A : never; }>;
export {};
//# sourceMappingURL=SemiProduct.d.ts.map

@@ -6,5 +6,9 @@ "use strict";

});
exports.productManyComposition = exports.productMany = exports.productFlatten = exports.productComposition = exports.nonEmptyTuple = exports.nonEmptyStruct = exports.andThenBind = void 0;
var _Function = /*#__PURE__*/require("@fp-ts/core/internal/Function");
exports.productManyComposition = exports.productMany = exports.productComposition = exports.nonEmptyTuple = exports.nonEmptyStruct = exports.element = exports.andThenBind = void 0;
var _Function = /*#__PURE__*/require("@fp-ts/core/Function");
/**
* @since 1.0.0
*/
/**
* Returns a default `product` composition.

@@ -14,3 +18,3 @@ *

*/
const productComposition = (F, G) => that => self => (0, _Function.pipe)(self, F.product(that), F.map(([ga, gb]) => (0, _Function.pipe)(ga, G.product(gb))));
const productComposition = (F, G) => (self, that) => (0, _Function.pipe)(F.product(self, that), F.map(([ga, gb]) => G.product(ga, gb)));
/**

@@ -22,3 +26,3 @@ * Returns a default `productMany` composition.

exports.productComposition = productComposition;
const productManyComposition = (F, G) => collection => self => (0, _Function.pipe)(self, F.productMany(collection), F.map(([ga, ...gas]) => (0, _Function.pipe)(ga, G.productMany(gas))));
const productManyComposition = (F, G) => (self, collection) => (0, _Function.pipe)(F.productMany(self, collection), F.map(([ga, ...gas]) => G.productMany(ga, gas)));
/**

@@ -31,6 +35,6 @@ * Returns a default `productMany` implementation (useful for tests).

exports.productManyComposition = productManyComposition;
const productMany = (Covariant, product) => collection => self => {
const productMany = (Covariant, product) => (self, collection) => {
let out = (0, _Function.pipe)(self, Covariant.map(a => [a]));
for (const fa of collection) {
out = (0, _Function.pipe)(out, product(fa), Covariant.map(([[head, ...tail], a]) => [head, ...tail, a]));
out = (0, _Function.pipe)(product(out, fa), Covariant.map(([[head, ...tail], a]) => [head, ...tail, a]));
}

@@ -43,3 +47,3 @@ return out;

exports.productMany = productMany;
const andThenBind = F => (name, that) => self => (0, _Function.pipe)(self, F.product(that), F.imap(([a, b]) => Object.assign({}, a, {
const andThenBind = F => (name, that) => self => (0, _Function.pipe)(F.product(self, that), F.imap(([a, b]) => Object.assign({}, a, {
[name]: b

@@ -51,11 +55,13 @@ }), ({

/**
* Adds an element to the end of a tuple.
*
* @since 1.0.0
*/
exports.andThenBind = andThenBind;
const productFlatten = F => that => self => (0, _Function.pipe)(self, F.product(that), F.imap(([a, b]) => [...a, b], ab => [ab.slice(0, -1), ab[ab.length - 1]]));
const element = F => that => self => (0, _Function.pipe)(F.product(self, that), F.imap(([a, b]) => [...a, b], ab => [ab.slice(0, -1), ab[ab.length - 1]]));
/**
* @since 1.0.0
*/
exports.productFlatten = productFlatten;
const nonEmptyTuple = F => (...components) => F.productMany(components.slice(1))(components[0]);
exports.element = element;
const nonEmptyTuple = F => (...components) => F.productMany(components[0], components.slice(1));
/**

@@ -67,3 +73,3 @@ * @since 1.0.0

const keys = Object.keys(fields);
return (0, _Function.pipe)(F.productMany(keys.slice(1).map(k => fields[k]))(fields[keys[0]]), F.imap(([value, ...values]) => {
return (0, _Function.pipe)(F.productMany(fields[keys[0]], keys.slice(1).map(k => fields[k])), F.imap(([value, ...values]) => {
const out = {

@@ -70,0 +76,0 @@ [keys[0]]: value

@@ -1,4 +0,1 @@

/**
* @since 1.0.0
*/
import type { Kind, TypeClass, TypeLambda } from "@fp-ts/core/HKT";

@@ -5,0 +2,0 @@ import type { Applicative } from "@fp-ts/core/typeclass/Applicative";

@@ -7,4 +7,8 @@ "use strict";

exports.traverseTap = exports.traverseComposition = exports.sequenceComposition = exports.sequence = void 0;
var _Function = /*#__PURE__*/require("@fp-ts/core/internal/Function");
var _Function = /*#__PURE__*/require("@fp-ts/core/Function");
/**
* @since 1.0.0
*/
/**
* Returns a default `traverse` composition.

@@ -11,0 +15,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 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

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