diff --git a/docs/modules/Apply.ts.md b/docs/modules/Apply.ts.md index d9e0d1598..1bf550e9a 100644 --- a/docs/modules/Apply.ts.md +++ b/docs/modules/Apply.ts.md @@ -80,19 +80,19 @@ Added in v3.0.0 export declare function ap( F: Apply4, G: Apply4 -): ( +): ( fa: Kind4> ) => (fab: Kind4 B>>) => Kind4> export declare function ap( F: Apply4, G: Apply3 -): ( +): ( fa: Kind4> ) => (fab: Kind4 B>>) => Kind4> export declare function ap( F: Apply4, G: Apply3C -): ( +): ( fa: Kind4> ) => (fab: Kind4 B>>) => Kind4> export declare function ap( @@ -113,37 +113,37 @@ export declare function ap( ): ( fa: Kind4> ) => (fab: Kind4 B>>) => Kind4> -export declare function ap( +export declare function ap( F: Apply3C, G: Apply4 -): ( +): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> -export declare function ap( +export declare function ap( F: Apply3C, G: Apply3 ): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> -export declare function ap( +export declare function ap( F: Apply3C, G: Apply3C -): ( +): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> -export declare function ap( +export declare function ap( F: Apply3C, G: Apply2 ): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> -export declare function ap( +export declare function ap( F: Apply3C, G: Apply2C ): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> -export declare function ap( +export declare function ap( F: Apply3C, G: Apply1 ): ( @@ -152,19 +152,19 @@ export declare function ap( export declare function ap( F: Apply3, G: Apply4 -): ( +): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> export declare function ap( F: Apply3, G: Apply3 -): ( +): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> export declare function ap( F: Apply3, G: Apply3C -): ( +): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> export declare function ap( @@ -185,56 +185,56 @@ export declare function ap( ): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> -export declare function ap( +export declare function ap( F: Apply2C, G: Apply4 ): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> -export declare function ap( +export declare function ap( F: Apply2C, G: Apply3 ): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> -export declare function ap( +export declare function ap( F: Apply2C, G: Apply3C ): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> -export declare function ap( +export declare function ap( F: Apply2C, G: Apply2 ): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> -export declare function ap( +export declare function ap( F: Apply2C, G: Apply2C ): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> -export declare function ap( +export declare function ap( F: Apply2C, G: Apply1 ): (fa: Kind2>) => (fab: Kind2 B>>) => Kind2> export declare function ap( F: Apply2, G: Apply4 -): ( +): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> export declare function ap( F: Apply2, G: Apply3 -): ( +): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> export declare function ap( F: Apply2, G: Apply3C -): ( +): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> export declare function ap( diff --git a/docs/modules/FromWriter.ts.md b/docs/modules/FromWriter.ts.md new file mode 100644 index 000000000..a5a440a87 --- /dev/null +++ b/docs/modules/FromWriter.ts.md @@ -0,0 +1,155 @@ +--- +title: FromWriter.ts +nav_order: 40 +parent: Modules +--- + +## FromWriter overview + +The `FromWriter` type class represents those data types which support accumulators. + +Added in v3.0.0 + +--- + +

Table of contents

+ +- [combinators](#combinators) + - [fromWriterK](#fromwriterk) +- [type classes](#type-classes) + - [FromWriter (interface)](#fromwriter-interface) + - [FromWriter1 (interface)](#fromwriter1-interface) + - [FromWriter2 (interface)](#fromwriter2-interface) + - [FromWriter2C (interface)](#fromwriter2c-interface) + - [FromWriter3 (interface)](#fromwriter3-interface) + - [FromWriter3C (interface)](#fromwriter3c-interface) + - [FromWriter4 (interface)](#fromwriter4-interface) + +--- + +# combinators + +## fromWriterK + +**Signature** + +```ts +export declare function fromWriterK( + F: FromWriter4 +):
, E, B>(f: (...a: A) => Writer) => (...a: A) => Kind4 +export declare function fromWriterK( + F: FromWriter3 +): , E, B>(f: (...a: A) => Writer) => (...a: A) => Kind3 +export declare function fromWriterK( + F: FromWriter3C +): , B>(f: (...a: A) => Writer) => (...a: A) => Kind3 +export declare function fromWriterK( + F: FromWriter2 +): , E, B>(f: (...a: A) => Writer) => (...a: A) => Kind2 +export declare function fromWriterK( + F: FromWriter2C +): , B>(f: (...a: A) => Writer) => (...a: A) => Kind2 +export declare function fromWriterK( + F: FromWriter1 +): , E, B>(f: (...a: A) => Writer) => (...a: A) => Kind +export declare function fromWriterK( + F: FromWriter +): , E, B>(f: (...a: A) => Writer) => (...a: A) => HKT2 +``` + +Added in v3.0.0 + +# type classes + +## FromWriter (interface) + +**Signature** + +```ts +export interface FromWriter { + readonly URI?: F + readonly fromWriter: (e: Writer) => HKT2 +} +``` + +Added in v3.0.0 + +## FromWriter1 (interface) + +**Signature** + +```ts +export interface FromWriter1 { + readonly URI?: F + readonly fromWriter: NaturalTransformation21 +} +``` + +Added in v3.0.0 + +## FromWriter2 (interface) + +**Signature** + +```ts +export interface FromWriter2 { + readonly URI?: F + readonly fromWriter: NaturalTransformation22 +} +``` + +Added in v3.0.0 + +## FromWriter2C (interface) + +**Signature** + +```ts +export interface FromWriter2C { + readonly URI?: F + readonly _E?: E + readonly fromWriter: NaturalTransformation22C +} +``` + +Added in v3.0.0 + +## FromWriter3 (interface) + +**Signature** + +```ts +export interface FromWriter3 { + readonly URI?: F + readonly fromWriter: NaturalTransformation23 +} +``` + +Added in v3.0.0 + +## FromWriter3C (interface) + +**Signature** + +```ts +export interface FromWriter3C { + readonly URI?: F + readonly _E?: E + readonly fromWriter: NaturalTransformation23C +} +``` + +Added in v3.0.0 + +## FromWriter4 (interface) + +**Signature** + +```ts +export interface FromWriter4 { + readonly URI?: F + readonly fromWriter: NaturalTransformation24 +} +``` + +Added in v3.0.0 diff --git a/docs/modules/Functor.ts.md b/docs/modules/Functor.ts.md index fe4c3e862..f01814c91 100644 --- a/docs/modules/Functor.ts.md +++ b/docs/modules/Functor.ts.md @@ -1,6 +1,6 @@ --- title: Functor.ts -nav_order: 41 +nav_order: 42 parent: Modules --- diff --git a/docs/modules/FunctorWithIndex.ts.md b/docs/modules/FunctorWithIndex.ts.md index bb8f808af..9f5aef49e 100644 --- a/docs/modules/FunctorWithIndex.ts.md +++ b/docs/modules/FunctorWithIndex.ts.md @@ -1,6 +1,6 @@ --- title: FunctorWithIndex.ts -nav_order: 42 +nav_order: 43 parent: Modules --- diff --git a/docs/modules/Group.ts.md b/docs/modules/Group.ts.md index 5d34162bb..92a42f686 100644 --- a/docs/modules/Group.ts.md +++ b/docs/modules/Group.ts.md @@ -1,6 +1,6 @@ --- title: Group.ts -nav_order: 43 +nav_order: 44 parent: Modules --- diff --git a/docs/modules/HKT.ts.md b/docs/modules/HKT.ts.md index ceb43b526..cc17711c9 100644 --- a/docs/modules/HKT.ts.md +++ b/docs/modules/HKT.ts.md @@ -1,6 +1,6 @@ --- title: HKT.ts -nav_order: 45 +nav_order: 46 parent: Modules --- diff --git a/docs/modules/HeytingAlgebra.ts.md b/docs/modules/HeytingAlgebra.ts.md index a44594c96..6520ed38b 100644 --- a/docs/modules/HeytingAlgebra.ts.md +++ b/docs/modules/HeytingAlgebra.ts.md @@ -1,6 +1,6 @@ --- title: HeytingAlgebra.ts -nav_order: 44 +nav_order: 45 parent: Modules --- diff --git a/docs/modules/IO.ts.md b/docs/modules/IO.ts.md index 13f186dde..c1bff0631 100644 --- a/docs/modules/IO.ts.md +++ b/docs/modules/IO.ts.md @@ -1,6 +1,6 @@ --- title: IO.ts -nav_order: 50 +nav_order: 51 parent: Modules --- diff --git a/docs/modules/IOEither.ts.md b/docs/modules/IOEither.ts.md index 3defe6efb..bc8edc71a 100644 --- a/docs/modules/IOEither.ts.md +++ b/docs/modules/IOEither.ts.md @@ -1,6 +1,6 @@ --- title: IOEither.ts -nav_order: 51 +nav_order: 52 parent: Modules --- diff --git a/docs/modules/IOOption.ts.md b/docs/modules/IOOption.ts.md index 5e8a2010c..7facce3ad 100644 --- a/docs/modules/IOOption.ts.md +++ b/docs/modules/IOOption.ts.md @@ -1,6 +1,6 @@ --- title: IOOption.ts -nav_order: 52 +nav_order: 53 parent: Modules --- diff --git a/docs/modules/Identity.ts.md b/docs/modules/Identity.ts.md index 8e63e4b07..de326deca 100644 --- a/docs/modules/Identity.ts.md +++ b/docs/modules/Identity.ts.md @@ -1,6 +1,6 @@ --- title: Identity.ts -nav_order: 46 +nav_order: 47 parent: Modules --- diff --git a/docs/modules/Invariant.ts.md b/docs/modules/Invariant.ts.md index 29c1d8931..0e06f4efa 100644 --- a/docs/modules/Invariant.ts.md +++ b/docs/modules/Invariant.ts.md @@ -1,6 +1,6 @@ --- title: Invariant.ts -nav_order: 49 +nav_order: 50 parent: Modules --- diff --git a/docs/modules/JoinSemilattice.ts.md b/docs/modules/JoinSemilattice.ts.md index 578a02383..855662e84 100644 --- a/docs/modules/JoinSemilattice.ts.md +++ b/docs/modules/JoinSemilattice.ts.md @@ -1,6 +1,6 @@ --- title: JoinSemilattice.ts -nav_order: 53 +nav_order: 54 parent: Modules --- diff --git a/docs/modules/Json.ts.md b/docs/modules/Json.ts.md index c0372d904..a75a7c146 100644 --- a/docs/modules/Json.ts.md +++ b/docs/modules/Json.ts.md @@ -1,6 +1,6 @@ --- title: Json.ts -nav_order: 54 +nav_order: 55 parent: Modules --- diff --git a/docs/modules/Lattice.ts.md b/docs/modules/Lattice.ts.md index 67bffeb53..a653a3d22 100644 --- a/docs/modules/Lattice.ts.md +++ b/docs/modules/Lattice.ts.md @@ -1,6 +1,6 @@ --- title: Lattice.ts -nav_order: 55 +nav_order: 56 parent: Modules --- diff --git a/docs/modules/Magma.ts.md b/docs/modules/Magma.ts.md index 55a579aec..f1ec63e50 100644 --- a/docs/modules/Magma.ts.md +++ b/docs/modules/Magma.ts.md @@ -1,6 +1,6 @@ --- title: Magma.ts -nav_order: 56 +nav_order: 57 parent: Modules --- diff --git a/docs/modules/MeetSemilattice.ts.md b/docs/modules/MeetSemilattice.ts.md index bf148caa9..f9267f984 100644 --- a/docs/modules/MeetSemilattice.ts.md +++ b/docs/modules/MeetSemilattice.ts.md @@ -1,6 +1,6 @@ --- title: MeetSemilattice.ts -nav_order: 57 +nav_order: 58 parent: Modules --- diff --git a/docs/modules/Monad.ts.md b/docs/modules/Monad.ts.md index 62d339f4d..0d224ae54 100644 --- a/docs/modules/Monad.ts.md +++ b/docs/modules/Monad.ts.md @@ -1,6 +1,6 @@ --- title: Monad.ts -nav_order: 58 +nav_order: 59 parent: Modules --- diff --git a/docs/modules/Monoid.ts.md b/docs/modules/Monoid.ts.md index a4e7f35cd..e5ee56add 100644 --- a/docs/modules/Monoid.ts.md +++ b/docs/modules/Monoid.ts.md @@ -1,6 +1,6 @@ --- title: Monoid.ts -nav_order: 59 +nav_order: 60 parent: Modules --- diff --git a/docs/modules/NaturalTransformation.ts.md b/docs/modules/NaturalTransformation.ts.md index bd9dcfb51..723944b60 100644 --- a/docs/modules/NaturalTransformation.ts.md +++ b/docs/modules/NaturalTransformation.ts.md @@ -1,6 +1,6 @@ --- title: NaturalTransformation.ts -nav_order: 60 +nav_order: 61 parent: Modules --- diff --git a/docs/modules/NonEmptyArray.ts.md b/docs/modules/NonEmptyArray.ts.md index 2a7d74bd1..0dbe4b989 100644 --- a/docs/modules/NonEmptyArray.ts.md +++ b/docs/modules/NonEmptyArray.ts.md @@ -1,6 +1,6 @@ --- title: NonEmptyArray.ts -nav_order: 61 +nav_order: 62 parent: Modules --- diff --git a/docs/modules/Option.ts.md b/docs/modules/Option.ts.md index 937afa702..53351ddba 100644 --- a/docs/modules/Option.ts.md +++ b/docs/modules/Option.ts.md @@ -1,6 +1,6 @@ --- title: Option.ts -nav_order: 63 +nav_order: 64 parent: Modules --- diff --git a/docs/modules/OptionT.ts.md b/docs/modules/OptionT.ts.md index 30851a2c7..02eda5642 100644 --- a/docs/modules/OptionT.ts.md +++ b/docs/modules/OptionT.ts.md @@ -1,6 +1,6 @@ --- title: OptionT.ts -nav_order: 64 +nav_order: 65 parent: Modules --- diff --git a/docs/modules/Ord.ts.md b/docs/modules/Ord.ts.md index 810a2beaa..9fec11931 100644 --- a/docs/modules/Ord.ts.md +++ b/docs/modules/Ord.ts.md @@ -1,6 +1,6 @@ --- title: Ord.ts -nav_order: 65 +nav_order: 66 parent: Modules --- diff --git a/docs/modules/Ordering.ts.md b/docs/modules/Ordering.ts.md index 7c9bbb676..5c6f4ec1f 100644 --- a/docs/modules/Ordering.ts.md +++ b/docs/modules/Ordering.ts.md @@ -1,6 +1,6 @@ --- title: Ordering.ts -nav_order: 66 +nav_order: 67 parent: Modules --- diff --git a/docs/modules/Pointed.ts.md b/docs/modules/Pointed.ts.md index 204e8979b..6038efcc4 100644 --- a/docs/modules/Pointed.ts.md +++ b/docs/modules/Pointed.ts.md @@ -1,6 +1,6 @@ --- title: Pointed.ts -nav_order: 67 +nav_order: 68 parent: Modules --- diff --git a/docs/modules/Predicate.ts.md b/docs/modules/Predicate.ts.md index 9e3ceb3d9..f0d723d23 100644 --- a/docs/modules/Predicate.ts.md +++ b/docs/modules/Predicate.ts.md @@ -1,6 +1,6 @@ --- title: Predicate.ts -nav_order: 68 +nav_order: 69 parent: Modules --- diff --git a/docs/modules/Profunctor.ts.md b/docs/modules/Profunctor.ts.md index 49fd33f9f..ed935410e 100644 --- a/docs/modules/Profunctor.ts.md +++ b/docs/modules/Profunctor.ts.md @@ -1,6 +1,6 @@ --- title: Profunctor.ts -nav_order: 69 +nav_order: 70 parent: Modules --- diff --git a/docs/modules/Random.ts.md b/docs/modules/Random.ts.md index a7b4cf53a..ee2a386f5 100644 --- a/docs/modules/Random.ts.md +++ b/docs/modules/Random.ts.md @@ -1,6 +1,6 @@ --- title: Random.ts -nav_order: 70 +nav_order: 71 parent: Modules --- diff --git a/docs/modules/Reader.ts.md b/docs/modules/Reader.ts.md index aa369e311..0c3966468 100644 --- a/docs/modules/Reader.ts.md +++ b/docs/modules/Reader.ts.md @@ -1,6 +1,6 @@ --- title: Reader.ts -nav_order: 71 +nav_order: 72 parent: Modules --- diff --git a/docs/modules/ReaderEither.ts.md b/docs/modules/ReaderEither.ts.md index a9a62fad9..c0c64a39d 100644 --- a/docs/modules/ReaderEither.ts.md +++ b/docs/modules/ReaderEither.ts.md @@ -1,6 +1,6 @@ --- title: ReaderEither.ts -nav_order: 72 +nav_order: 73 parent: Modules --- diff --git a/docs/modules/ReaderIO.ts.md b/docs/modules/ReaderIO.ts.md index b43424fbd..c76621d87 100644 --- a/docs/modules/ReaderIO.ts.md +++ b/docs/modules/ReaderIO.ts.md @@ -1,6 +1,6 @@ --- title: ReaderIO.ts -nav_order: 73 +nav_order: 74 parent: Modules --- @@ -141,7 +141,7 @@ The `W` suffix (short for **W**idening) means that the environment types will be **Signature** ```ts -export declare const chainW: ( +export declare const chainW: ( f: (a: A) => ReaderIO ) => (ma: ReaderIO) => ReaderIO ``` @@ -278,7 +278,7 @@ Derivable from `Chain`. **Signature** ```ts -export declare const chainFirstW: ( +export declare const chainFirstW: ( f: (a: A) => ReaderIO ) => (ma: ReaderIO) => ReaderIO ``` @@ -600,7 +600,7 @@ The `W` suffix (short for **W**idening) means that the environment types will be **Signature** ```ts -export declare const apSW: ( +export declare const apSW: ( name: Exclude, fb: ReaderIO ) => (fa: ReaderIO) => ReaderIO diff --git a/docs/modules/ReaderT.ts.md b/docs/modules/ReaderT.ts.md index 4c1ee1900..3ac5b5f8a 100644 --- a/docs/modules/ReaderT.ts.md +++ b/docs/modules/ReaderT.ts.md @@ -1,6 +1,6 @@ --- title: ReaderT.ts -nav_order: 74 +nav_order: 75 parent: Modules --- diff --git a/docs/modules/ReaderTask.ts.md b/docs/modules/ReaderTask.ts.md index 626385097..e895d72a2 100644 --- a/docs/modules/ReaderTask.ts.md +++ b/docs/modules/ReaderTask.ts.md @@ -1,6 +1,6 @@ --- title: ReaderTask.ts -nav_order: 75 +nav_order: 76 parent: Modules --- diff --git a/docs/modules/ReaderTaskEither.ts.md b/docs/modules/ReaderTaskEither.ts.md index 8aa52e925..6b5306b54 100644 --- a/docs/modules/ReaderTaskEither.ts.md +++ b/docs/modules/ReaderTaskEither.ts.md @@ -1,6 +1,6 @@ --- title: ReaderTaskEither.ts -nav_order: 76 +nav_order: 77 parent: Modules --- diff --git a/docs/modules/ReaderTaskWriter.ts.md b/docs/modules/ReaderTaskWriter.ts.md new file mode 100644 index 000000000..90e55fccd --- /dev/null +++ b/docs/modules/ReaderTaskWriter.ts.md @@ -0,0 +1,572 @@ +--- +title: ReaderTaskWriter.ts +nav_order: 78 +parent: Modules +--- + +## ReaderTaskWriter overview + +Added in v3.0.0 + +--- + +

Table of contents

+ +- [combinators](#combinators) + - [flap](#flap) + - [fromReaderWriterK](#fromreaderwriterk) + - [fromTaskWriterK](#fromtaskwriterk) + - [fromWriterK](#fromwriterk) + - [local](#local) +- [constructors](#constructors) + - [asksReaderTaskWriter](#asksreadertaskwriter) + - [asksReaderTaskWriterW](#asksreadertaskwriterw) + - [fromIO](#fromio) + - [fromReader](#fromreader) + - [fromReaderTask](#fromreadertask) + - [fromTask](#fromtask) + - [fromTaskWriter](#fromtaskwriter) + - [tell](#tell) +- [instances](#instances) + - [Bifunctor](#bifunctor) + - [FromWriter](#fromwriter) + - [Functor](#functor) + - [URI (type alias)](#uri-type-alias) + - [getApplicative](#getapplicative) + - [getApply](#getapply) + - [getChain](#getchain) + - [getFromIO](#getfromio) + - [getFromReader](#getfromreader) + - [getFromTask](#getfromtask) + - [getMonad](#getmonad) + - [getPointed](#getpointed) +- [model](#model) + - [ReaderTaskWriter (interface)](#readertaskwriter-interface) +- [natural transformations](#natural-transformations) + - [fromReaderWriter](#fromreaderwriter) + - [fromWriter](#fromwriter) +- [type class operations](#type-class-operations) + - [bimap](#bimap) + - [map](#map) + - [mapLeft](#mapleft) +- [utils](#utils) + - [bindTo](#bindto) + - [censor](#censor) + - [evaluate](#evaluate) + - [execute](#execute) + - [fst](#fst) + - [listen](#listen) + - [listens](#listens) + - [mapFst](#mapfst) + - [mapSnd](#mapsnd) + - [pass](#pass) + - [snd](#snd) + - [swap](#swap) + - [tupled](#tupled) + +--- + +# combinators + +## flap + +Derivable from `Functor`. + +**Signature** + +```ts +export declare const flap:
(a: A) => (fab: ReaderTaskWriter B>) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## fromReaderWriterK + +**Signature** + +```ts +export declare const fromReaderWriterK: ( + f: (...a: A) => Reader> +) => (...a: A) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## fromTaskWriterK + +**Signature** + +```ts +export declare const fromTaskWriterK: ( + f: (...a: A) => Task> +) => (...a: A) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## fromWriterK + +**Signature** + +```ts +export declare const fromWriterK: (f: (...a: A) => Writer) => (...a: A) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## local + +Changes the value of the local context during the execution of the action `ma` (similar to `Contravariant`'s +`contramap`). + +**Signature** + +```ts +export declare const local: ( + f: (r2: R2) => R1 +) => (ma: ReaderTaskWriter) => ReaderTaskWriter +``` + +Added in v3.0.0 + +# constructors + +## asksReaderTaskWriter + +**Signature** + +```ts +export declare const asksReaderTaskWriter: ( + f: (r: R) => ReaderTaskWriter +) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## asksReaderTaskWriterW + +Less strict version of [`asksReaderTaskWriter`](#asksreadertaskwriter). + +**Signature** + +```ts +export declare const asksReaderTaskWriterW: ( + f: (r1: R1) => ReaderTaskWriter +) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## fromIO + +**Signature** + +```ts +export declare const fromIO: (w: W) => (fa: IO) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## fromReader + +**Signature** + +```ts +export declare const fromReader: (w: W) => (fa: Reader) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## fromReaderTask + +**Signature** + +```ts +export declare const fromReaderTask: (w: W) => (a: RT.ReaderTask) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## fromTask + +**Signature** + +```ts +export declare const fromTask: (w: W) => (fa: Task) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## fromTaskWriter + +**Signature** + +```ts +export declare const fromTaskWriter: (a: Task>) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## tell + +Appends a value to the accumulator + +**Signature** + +```ts +export declare const tell: (w: W) => ReaderTaskWriter +``` + +Added in v3.0.0 + +# instances + +## Bifunctor + +**Signature** + +```ts +export declare const Bifunctor: Bifunctor3<'ReaderTaskWriter'> +``` + +Added in v3.0.0 + +## FromWriter + +**Signature** + +```ts +export declare const FromWriter: FromWriter3<'ReaderTaskWriter'> +``` + +Added in v3.0.0 + +## Functor + +**Signature** + +```ts +export declare const Functor: Functor3<'ReaderTaskWriter'> +``` + +Added in v3.0.0 + +## URI (type alias) + +**Signature** + +```ts +export type URI = 'ReaderTaskWriter' +``` + +Added in v3.0.0 + +## getApplicative + +**Signature** + +```ts +export declare const getApplicative: (A: Apply2, M: Monoid) => Applicative3C<'ReaderTaskWriter', W> +``` + +Added in v3.0.0 + +## getApply + +**Signature** + +```ts +export declare const getApply: (A: Apply2, S: Semigroup) => Apply3C<'ReaderTaskWriter', W> +``` + +Added in v3.0.0 + +## getChain + +**Signature** + +```ts +export declare const getChain: (S: Semigroup) => Chain3C<'ReaderTaskWriter', W> +``` + +Added in v3.0.0 + +## getFromIO + +**Signature** + +```ts +export declare const getFromIO: (M: Monoid) => FromIO3C<'ReaderTaskWriter', W> +``` + +Added in v3.0.0 + +## getFromReader + +**Signature** + +```ts +export declare const getFromReader: (M: Monoid) => FromReader3C<'ReaderTaskWriter', W> +``` + +Added in v3.0.0 + +## getFromTask + +**Signature** + +```ts +export declare const getFromTask: (M: Monoid) => FromTask3C<'ReaderTaskWriter', W> +``` + +Added in v3.0.0 + +## getMonad + +**Signature** + +```ts +export declare const getMonad: (M: Monoid) => Monad3C<'ReaderTaskWriter', W> +``` + +Added in v3.0.0 + +## getPointed + +**Signature** + +```ts +export declare const getPointed: (M: Monoid) => Pointed3C<'ReaderTaskWriter', W> +``` + +Added in v3.0.0 + +# model + +## ReaderTaskWriter (interface) + +**Signature** + +```ts +export interface ReaderTaskWriter extends Reader>> {} +``` + +Added in v3.0.0 + +# natural transformations + +## fromReaderWriter + +**Signature** + +```ts +export declare const fromReaderWriter: (fa: Reader>) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## fromWriter + +**Signature** + +```ts +export declare const fromWriter: (w: Writer) => ReaderTaskWriter +``` + +Added in v3.0.0 + +# type class operations + +## bimap + +Map a pair of functions over the two type arguments of the bifunctor. + +**Signature** + +```ts +export declare const bimap: ( + f: (e: E) => G, + g: (a: A) => B +) => (fea: ReaderTaskWriter) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## map + +`map` can be used to turn functions `(a: A) => B` into functions `(fa: F) => F` whose argument and return types +use the type constructor `F` to represent some computational context. + +**Signature** + +```ts +export declare const map: (f: (a: A) => B) => (fa: ReaderTaskWriter) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## mapLeft + +**Signature** + +```ts +export declare const mapLeft: ( + f: (e: E) => G +) => (fea: ReaderTaskWriter) => ReaderTaskWriter +``` + +Added in v3.0.0 + +# utils + +## bindTo + +**Signature** + +```ts +export declare const bindTo: ( + name: N +) => (fa: ReaderTaskWriter) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## censor + +**Signature** + +```ts +export declare const censor: (f: (w: W) => W) => (fwa: ReaderTaskWriter) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## evaluate + +Alias of [`fst`](#fst). + +**Signature** + +```ts +export declare const evaluate: (t: ReaderTaskWriter) => RT.ReaderTask +``` + +Added in v3.0.0 + +## execute + +Alias of [`snd`](#snd). + +**Signature** + +```ts +export declare const execute: (t: ReaderTaskWriter) => RT.ReaderTask +``` + +Added in v3.0.0 + +## fst + +**Signature** + +```ts +export declare const fst: (t: ReaderTaskWriter) => RT.ReaderTask +``` + +Added in v3.0.0 + +## listen + +**Signature** + +```ts +export declare const listen: (fwa: ReaderTaskWriter) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## listens + +**Signature** + +```ts +export declare const listens: ( + f: (w: W) => B +) => (fwa: ReaderTaskWriter) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## mapFst + +Maps a function over the first component of a `Writer`. + +Alias of [`map`](#map) + +**Signature** + +```ts +export declare const mapFst: ( + f: (a: A) => B +) => (fa: ReaderTaskWriter) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## mapSnd + +Maps a function over the second component of a `Writer`. + +Alias of [`mapLeft`](#mapleft) + +**Signature** + +```ts +export declare const mapSnd: ( + f: (e: E) => G +) => (fea: ReaderTaskWriter) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## pass + +**Signature** + +```ts +export declare const pass: ( + fwa: ReaderTaskWriter W]> +) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## snd + +**Signature** + +```ts +export declare const snd: (t: ReaderTaskWriter) => RT.ReaderTask +``` + +Added in v3.0.0 + +## swap + +**Signature** + +```ts +export declare const swap: (t: ReaderTaskWriter) => ReaderTaskWriter +``` + +Added in v3.0.0 + +## tupled + +**Signature** + +```ts +export declare const tupled: (fa: ReaderTaskWriter) => ReaderTaskWriter +``` + +Added in v3.0.0 diff --git a/docs/modules/ReadonlyArray.ts.md b/docs/modules/ReadonlyArray.ts.md index 2dc1f277b..559a66b34 100644 --- a/docs/modules/ReadonlyArray.ts.md +++ b/docs/modules/ReadonlyArray.ts.md @@ -1,6 +1,6 @@ --- title: ReadonlyArray.ts -nav_order: 77 +nav_order: 79 parent: Modules --- diff --git a/docs/modules/ReadonlyMap.ts.md b/docs/modules/ReadonlyMap.ts.md index 1bdec7947..772914453 100644 --- a/docs/modules/ReadonlyMap.ts.md +++ b/docs/modules/ReadonlyMap.ts.md @@ -1,6 +1,6 @@ --- title: ReadonlyMap.ts -nav_order: 78 +nav_order: 80 parent: Modules --- diff --git a/docs/modules/ReadonlyNonEmptyArray.ts.md b/docs/modules/ReadonlyNonEmptyArray.ts.md index dbf987fad..34279a33c 100644 --- a/docs/modules/ReadonlyNonEmptyArray.ts.md +++ b/docs/modules/ReadonlyNonEmptyArray.ts.md @@ -1,6 +1,6 @@ --- title: ReadonlyNonEmptyArray.ts -nav_order: 79 +nav_order: 81 parent: Modules --- diff --git a/docs/modules/ReadonlyRecord.ts.md b/docs/modules/ReadonlyRecord.ts.md index 28af1b7e8..f0a55fe77 100644 --- a/docs/modules/ReadonlyRecord.ts.md +++ b/docs/modules/ReadonlyRecord.ts.md @@ -1,6 +1,6 @@ --- title: ReadonlyRecord.ts -nav_order: 80 +nav_order: 82 parent: Modules --- diff --git a/docs/modules/ReadonlySet.ts.md b/docs/modules/ReadonlySet.ts.md index 7a6966150..048bd4382 100644 --- a/docs/modules/ReadonlySet.ts.md +++ b/docs/modules/ReadonlySet.ts.md @@ -1,6 +1,6 @@ --- title: ReadonlySet.ts -nav_order: 81 +nav_order: 83 parent: Modules --- diff --git a/docs/modules/Refinement.ts.md b/docs/modules/Refinement.ts.md index e38966657..2095107d6 100644 --- a/docs/modules/Refinement.ts.md +++ b/docs/modules/Refinement.ts.md @@ -1,6 +1,6 @@ --- title: Refinement.ts -nav_order: 82 +nav_order: 84 parent: Modules --- diff --git a/docs/modules/Ring.ts.md b/docs/modules/Ring.ts.md index 9d5e55bb3..197a715b3 100644 --- a/docs/modules/Ring.ts.md +++ b/docs/modules/Ring.ts.md @@ -1,6 +1,6 @@ --- title: Ring.ts -nav_order: 83 +nav_order: 85 parent: Modules --- diff --git a/docs/modules/Semigroup.ts.md b/docs/modules/Semigroup.ts.md index e8ac622bd..fa034d43c 100644 --- a/docs/modules/Semigroup.ts.md +++ b/docs/modules/Semigroup.ts.md @@ -1,6 +1,6 @@ --- title: Semigroup.ts -nav_order: 84 +nav_order: 86 parent: Modules --- diff --git a/docs/modules/Semigroupoid.ts.md b/docs/modules/Semigroupoid.ts.md index 69b27e912..c7aad3ce3 100644 --- a/docs/modules/Semigroupoid.ts.md +++ b/docs/modules/Semigroupoid.ts.md @@ -1,6 +1,6 @@ --- title: Semigroupoid.ts -nav_order: 85 +nav_order: 87 parent: Modules --- diff --git a/docs/modules/Semiring.ts.md b/docs/modules/Semiring.ts.md index 8678df8f7..f42c5dba4 100644 --- a/docs/modules/Semiring.ts.md +++ b/docs/modules/Semiring.ts.md @@ -1,6 +1,6 @@ --- title: Semiring.ts -nav_order: 86 +nav_order: 88 parent: Modules --- diff --git a/docs/modules/Separated.ts.md b/docs/modules/Separated.ts.md index e984d6f61..afa6a5e80 100644 --- a/docs/modules/Separated.ts.md +++ b/docs/modules/Separated.ts.md @@ -1,6 +1,6 @@ --- title: Separated.ts -nav_order: 87 +nav_order: 89 parent: Modules --- diff --git a/docs/modules/Show.ts.md b/docs/modules/Show.ts.md index fb293fbdf..a2a2128b6 100644 --- a/docs/modules/Show.ts.md +++ b/docs/modules/Show.ts.md @@ -1,6 +1,6 @@ --- title: Show.ts -nav_order: 88 +nav_order: 90 parent: Modules --- diff --git a/docs/modules/State.ts.md b/docs/modules/State.ts.md index 8bbc462ea..494084e52 100644 --- a/docs/modules/State.ts.md +++ b/docs/modules/State.ts.md @@ -1,6 +1,6 @@ --- title: State.ts -nav_order: 89 +nav_order: 91 parent: Modules --- diff --git a/docs/modules/StateReaderTaskEither.ts.md b/docs/modules/StateReaderTaskEither.ts.md index 9659dac96..a8d9ca4db 100644 --- a/docs/modules/StateReaderTaskEither.ts.md +++ b/docs/modules/StateReaderTaskEither.ts.md @@ -1,6 +1,6 @@ --- title: StateReaderTaskEither.ts -nav_order: 90 +nav_order: 92 parent: Modules --- diff --git a/docs/modules/StateT.ts.md b/docs/modules/StateT.ts.md index 6ea48fd88..e35150dfc 100644 --- a/docs/modules/StateT.ts.md +++ b/docs/modules/StateT.ts.md @@ -1,6 +1,6 @@ --- title: StateT.ts -nav_order: 91 +nav_order: 93 parent: Modules --- diff --git a/docs/modules/Store.ts.md b/docs/modules/Store.ts.md index e4344dcfd..8ca4e084c 100644 --- a/docs/modules/Store.ts.md +++ b/docs/modules/Store.ts.md @@ -1,6 +1,6 @@ --- title: Store.ts -nav_order: 92 +nav_order: 94 parent: Modules --- diff --git a/docs/modules/Strong.ts.md b/docs/modules/Strong.ts.md index 37b2fe5dd..a726c957b 100644 --- a/docs/modules/Strong.ts.md +++ b/docs/modules/Strong.ts.md @@ -1,6 +1,6 @@ --- title: Strong.ts -nav_order: 94 +nav_order: 96 parent: Modules --- diff --git a/docs/modules/Task.ts.md b/docs/modules/Task.ts.md index a5a9633fa..a598d5c16 100644 --- a/docs/modules/Task.ts.md +++ b/docs/modules/Task.ts.md @@ -1,6 +1,6 @@ --- title: Task.ts -nav_order: 96 +nav_order: 98 parent: Modules --- diff --git a/docs/modules/TaskEither.ts.md b/docs/modules/TaskEither.ts.md index 442566ea3..1d4ae91c2 100644 --- a/docs/modules/TaskEither.ts.md +++ b/docs/modules/TaskEither.ts.md @@ -1,6 +1,6 @@ --- title: TaskEither.ts -nav_order: 97 +nav_order: 99 parent: Modules --- diff --git a/docs/modules/TaskOption.ts.md b/docs/modules/TaskOption.ts.md index 9891da0db..a8a48952e 100644 --- a/docs/modules/TaskOption.ts.md +++ b/docs/modules/TaskOption.ts.md @@ -1,6 +1,6 @@ --- title: TaskOption.ts -nav_order: 98 +nav_order: 100 parent: Modules --- diff --git a/docs/modules/TaskThese.ts.md b/docs/modules/TaskThese.ts.md index 3827c81bf..91a4b9903 100644 --- a/docs/modules/TaskThese.ts.md +++ b/docs/modules/TaskThese.ts.md @@ -1,6 +1,6 @@ --- title: TaskThese.ts -nav_order: 99 +nav_order: 101 parent: Modules --- diff --git a/docs/modules/These.ts.md b/docs/modules/These.ts.md index 8c7b37a40..4ad66f514 100644 --- a/docs/modules/These.ts.md +++ b/docs/modules/These.ts.md @@ -1,6 +1,6 @@ --- title: These.ts -nav_order: 100 +nav_order: 102 parent: Modules --- diff --git a/docs/modules/TheseT.ts.md b/docs/modules/TheseT.ts.md index fe231aaf8..61b0026c6 100644 --- a/docs/modules/TheseT.ts.md +++ b/docs/modules/TheseT.ts.md @@ -1,6 +1,6 @@ --- title: TheseT.ts -nav_order: 101 +nav_order: 103 parent: Modules --- diff --git a/docs/modules/Traced.ts.md b/docs/modules/Traced.ts.md index 95bc9a5a1..8dbb96696 100644 --- a/docs/modules/Traced.ts.md +++ b/docs/modules/Traced.ts.md @@ -1,6 +1,6 @@ --- title: Traced.ts -nav_order: 102 +nav_order: 104 parent: Modules --- diff --git a/docs/modules/Traversable.ts.md b/docs/modules/Traversable.ts.md index e3de28a7b..d64798444 100644 --- a/docs/modules/Traversable.ts.md +++ b/docs/modules/Traversable.ts.md @@ -1,6 +1,6 @@ --- title: Traversable.ts -nav_order: 103 +nav_order: 105 parent: Modules --- diff --git a/docs/modules/TraversableWithIndex.ts.md b/docs/modules/TraversableWithIndex.ts.md index 756173c41..5917da5cd 100644 --- a/docs/modules/TraversableWithIndex.ts.md +++ b/docs/modules/TraversableWithIndex.ts.md @@ -1,6 +1,6 @@ --- title: TraversableWithIndex.ts -nav_order: 104 +nav_order: 106 parent: Modules --- diff --git a/docs/modules/Tree.ts.md b/docs/modules/Tree.ts.md index fdfee1c15..032739b97 100644 --- a/docs/modules/Tree.ts.md +++ b/docs/modules/Tree.ts.md @@ -1,6 +1,6 @@ --- title: Tree.ts -nav_order: 105 +nav_order: 107 parent: Modules --- diff --git a/docs/modules/Tuple2.ts.md b/docs/modules/Tuple2.ts.md deleted file mode 100644 index 3b5d0abee..000000000 --- a/docs/modules/Tuple2.ts.md +++ /dev/null @@ -1,390 +0,0 @@ ---- -title: Tuple2.ts -nav_order: 107 -parent: Modules ---- - -## Tuple2 overview - -Added in v3.0.0 - ---- - -

Table of contents

- -- [Bifunctor](#bifunctor) - - [bimap](#bimap) - - [mapSnd](#mapsnd) -- [Extend](#extend) - - [extend](#extend) -- [Extract](#extract) - - [extract](#extract) -- [Foldable](#foldable) - - [foldMap](#foldmap) - - [reduce](#reduce) - - [reduceRight](#reduceright) -- [Functor](#functor) - - [mapFst](#mapfst) -- [Semigroupoid](#semigroupoid) - - [compose](#compose) -- [combinators](#combinators) - - [flap](#flap) - - [swap](#swap) -- [derivable combinators](#derivable-combinators) - - [duplicate](#duplicate) -- [instances](#instances) - - [Bifunctor](#bifunctor-1) - - [Comonad](#comonad) - - [Foldable](#foldable-1) - - [Functor](#functor-1) - - [Semigroupoid](#semigroupoid-1) - - [Traversable](#traversable) - - [URI (type alias)](#uri-type-alias) - - [getApplicative](#getapplicative) - - [getApply](#getapply) - - [getChain](#getchain) - - [getChainRec](#getchainrec) - - [getMonad](#getmonad) - - [getPointed](#getpointed) -- [utils](#utils) - - [Tuple2 (type alias)](#tuple2-type-alias) - - [fst](#fst) - - [snd](#snd) - - [traverse](#traverse) - - [tuple2](#tuple2) - ---- - -# Bifunctor - -## bimap - -Map a pair of functions over the two type arguments of the bifunctor. - -**Signature** - -```ts -export declare const bimap: (mapSnd: (e: E) => G, mapFst: (a: A) => B) => (t: Tuple2) => Tuple2 -``` - -Added in v3.0.0 - -## mapSnd - -Map a function over the second component of a `Tuple2`. - -This is the `mapLeft` operation of the `Bifunctor` instance. - -**Signature** - -```ts -export declare const mapSnd: (f: (e: E) => G) =>
(fea: Tuple2) => Tuple2 -``` - -Added in v3.0.0 - -# Extend - -## extend - -**Signature** - -```ts -export declare const extend: (f: (wa: Tuple2) => B) => (wa: Tuple2) => Tuple2 -``` - -Added in v3.0.0 - -# Extract - -## extract - -**Signature** - -```ts -export declare const extract: (wa: Tuple2) => A -``` - -Added in v3.0.0 - -# Foldable - -## foldMap - -**Signature** - -```ts -export declare const foldMap: (M: Monoid) => (f: (a: A) => M) => (fa: Tuple2) => M -``` - -Added in v3.0.0 - -## reduce - -**Signature** - -```ts -export declare const reduce: (b: B, f: (b: B, a: A) => B) => (fa: Tuple2) => B -``` - -Added in v3.0.0 - -## reduceRight - -**Signature** - -```ts -export declare const reduceRight: (b: B, f: (a: A, b: B) => B) => (fa: Tuple2) => B -``` - -Added in v3.0.0 - -# Functor - -## mapFst - -Map a function over the first component of a `Tuple2`. - -This is the `map` operation of the `Functor` instance. - -**Signature** - -```ts -export declare const mapFst: (f: (a: A) => B) => (fa: Tuple2) => Tuple2 -``` - -Added in v3.0.0 - -# Semigroupoid - -## compose - -**Signature** - -```ts -export declare const compose: (bc: Tuple2) => (ab: Tuple2) => Tuple2 -``` - -Added in v3.0.0 - -# combinators - -## flap - -Derivable from `Functor`. - -**Signature** - -```ts -export declare const flap: (a: A) => (fab: Tuple2 B>) => Tuple2 -``` - -Added in v3.0.0 - -## swap - -**Signature** - -```ts -export declare const swap: (t: Tuple2) => Tuple2 -``` - -Added in v3.0.0 - -# derivable combinators - -## duplicate - -Derivable from `Extend`. - -**Signature** - -```ts -export declare const duplicate: (t: Tuple2) => Tuple2> -``` - -Added in v3.0.0 - -# instances - -## Bifunctor - -**Signature** - -```ts -export declare const Bifunctor: Bifunctor2<'Tuple2'> -``` - -Added in v3.0.0 - -## Comonad - -**Signature** - -```ts -export declare const Comonad: Comonad2<'Tuple2'> -``` - -Added in v3.0.0 - -## Foldable - -**Signature** - -```ts -export declare const Foldable: Foldable2<'Tuple2'> -``` - -Added in v3.0.0 - -## Functor - -**Signature** - -```ts -export declare const Functor: Functor2<'Tuple2'> -``` - -Added in v3.0.0 - -## Semigroupoid - -**Signature** - -```ts -export declare const Semigroupoid: Semigroupoid2<'Tuple2'> -``` - -Added in v3.0.0 - -## Traversable - -**Signature** - -```ts -export declare const Traversable: Traversable2<'Tuple2'> -``` - -Added in v3.0.0 - -## URI (type alias) - -**Signature** - -```ts -export type URI = 'Tuple2' -``` - -Added in v3.0.0 - -## getApplicative - -**Signature** - -```ts -export declare const getApplicative: (M: Monoid) => Applicative2C<'Tuple2', M> -``` - -Added in v3.0.0 - -## getApply - -**Signature** - -```ts -export declare const getApply: (S: Semigroup) => Apply2C<'Tuple2', S> -``` - -Added in v3.0.0 - -## getChain - -**Signature** - -```ts -export declare const getChain: (S: Semigroup) => Chain2C<'Tuple2', S> -``` - -Added in v3.0.0 - -## getChainRec - -**Signature** - -```ts -export declare function getChainRec(M: Monoid): ChainRec2C -``` - -Added in v3.0.0 - -## getMonad - -**Signature** - -```ts -export declare const getMonad: (M: Monoid) => Monad2C<'Tuple2', M> -``` - -Added in v3.0.0 - -## getPointed - -**Signature** - -```ts -export declare const getPointed: (M: Monoid) => Pointed2C<'Tuple2', M> -``` - -Added in v3.0.0 - -# utils - -## Tuple2 (type alias) - -**Signature** - -```ts -export type Tuple2 = readonly [A, E] -``` - -Added in v3.0.0 - -## fst - -**Signature** - -```ts -export declare const fst: (t: Tuple2) => A -``` - -Added in v3.0.0 - -## snd - -**Signature** - -```ts -export declare const snd: (t: Tuple2) => E -``` - -Added in v3.0.0 - -## traverse - -**Signature** - -```ts -export declare const traverse: Traverse2<'Tuple2'> -``` - -Added in v3.0.0 - -## tuple2 - -**Signature** - -```ts -export declare const tuple2: (a: A, e: E) => Tuple2 -``` - -Added in v3.0.0 diff --git a/docs/modules/Unfoldable.ts.md b/docs/modules/Unfoldable.ts.md index 29e5c09d1..fc1c997fc 100644 --- a/docs/modules/Unfoldable.ts.md +++ b/docs/modules/Unfoldable.ts.md @@ -1,6 +1,6 @@ --- title: Unfoldable.ts -nav_order: 108 +nav_order: 109 parent: Modules --- diff --git a/docs/modules/Witherable.ts.md b/docs/modules/Witherable.ts.md index c19e79a5b..39915eb1d 100644 --- a/docs/modules/Witherable.ts.md +++ b/docs/modules/Witherable.ts.md @@ -1,6 +1,6 @@ --- title: Witherable.ts -nav_order: 110 +nav_order: 111 parent: Modules --- diff --git a/docs/modules/Writer.ts.md b/docs/modules/Writer.ts.md index 776fe04ff..113887a7e 100644 --- a/docs/modules/Writer.ts.md +++ b/docs/modules/Writer.ts.md @@ -1,6 +1,6 @@ --- title: Writer.ts -nav_order: 111 +nav_order: 112 parent: Modules --- @@ -12,47 +12,54 @@ Added in v3.0.0

Table of contents

-- [Functor](#functor) - - [map](#map) - [combinators](#combinators) - [censor](#censor) - [flap](#flap) - [listen](#listen) - [listens](#listens) - [pass](#pass) + - [swap](#swap) - [constructors](#constructors) + - [fromIdentity](#fromidentity) - [tell](#tell) - [instances](#instances) - - [Functor](#functor-1) + - [Bifunctor](#bifunctor) + - [Comonad](#comonad) + - [Foldable](#foldable) + - [Functor](#functor) + - [Semigroupoid](#semigroupoid) + - [Traversable](#traversable) - [URI (type alias)](#uri-type-alias) - [getApplicative](#getapplicative) - [getApply](#getapply) - [getChain](#getchain) + - [getChainRec](#getchainrec) - [getMonad](#getmonad) - [getPointed](#getpointed) - [model](#model) - - [Writer (interface)](#writer-interface) + - [Writer (type alias)](#writer-type-alias) +- [type class operations](#type-class-operations) + - [bimap](#bimap) + - [compose](#compose) + - [duplicate](#duplicate) + - [extend](#extend) + - [extract](#extract) + - [foldMap](#foldmap) + - [map](#map) + - [mapLeft](#mapleft) + - [reduce](#reduce) + - [reduceRight](#reduceright) + - [traverse](#traverse) - [utils](#utils) - [evaluate](#evaluate) - [execute](#execute) + - [fst](#fst) + - [mapFst](#mapfst) + - [mapSnd](#mapsnd) + - [snd](#snd) --- -# Functor - -## map - -`map` can be used to turn functions `(a: A) => B` into functions `(fa: F
) => F` whose argument and return types -use the type constructor `F` to represent some computational context. - -**Signature** - -```ts -export declare const map: (f: (a: A) => B) => (fa: Writer) => Writer -``` - -Added in v3.0.0 - # combinators ## censor @@ -115,8 +122,28 @@ export declare const pass: (fa: Writer W]>) => W Added in v3.0.0 +## swap + +**Signature** + +```ts +export declare const swap: (t: Writer) => Writer +``` + +Added in v3.0.0 + # constructors +## fromIdentity + +**Signature** + +```ts +export declare const fromIdentity: (w: W) => (a: A) => Writer +``` + +Added in v3.0.0 + ## tell Appends a value to the accumulator @@ -131,6 +158,36 @@ Added in v3.0.0 # instances +## Bifunctor + +**Signature** + +```ts +export declare const Bifunctor: Bifunctor2<'Writer'> +``` + +Added in v3.0.0 + +## Comonad + +**Signature** + +```ts +export declare const Comonad: Comonad2<'Writer'> +``` + +Added in v3.0.0 + +## Foldable + +**Signature** + +```ts +export declare const Foldable: Foldable2<'Writer'> +``` + +Added in v3.0.0 + ## Functor **Signature** @@ -141,6 +198,26 @@ export declare const Functor: Functor2<'Writer'> Added in v3.0.0 +## Semigroupoid + +**Signature** + +```ts +export declare const Semigroupoid: Semigroupoid2<'Writer'> +``` + +Added in v3.0.0 + +## Traversable + +**Signature** + +```ts +export declare const Traversable: Traversable2<'Writer'> +``` + +Added in v3.0.0 + ## URI (type alias) **Signature** @@ -181,6 +258,16 @@ export declare const getChain: (S: Semigroup) => Chain2C<'Writer', W> Added in v3.0.0 +## getChainRec + +**Signature** + +```ts +export declare function getChainRec(M: Monoid): ChainRec2C +``` + +Added in v3.0.0 + ## getMonad **Signature** @@ -203,14 +290,131 @@ Added in v3.0.0 # model -## Writer (interface) +## Writer (type alias) + +**Signature** + +```ts +export type Writer = readonly [A, W] +``` + +Added in v3.0.0 + +# type class operations + +## bimap + +Map a pair of functions over the two type arguments of the bifunctor. + +**Signature** + +```ts +export declare const bimap: (mapSnd: (e: W) => G, mapFst: (a: A) => B) => (t: Writer) => Writer +``` + +Added in v3.0.0 + +## compose + +**Signature** + +```ts +export declare const compose: (bc: Writer) => (ab: Writer) => Writer +``` + +Added in v3.0.0 + +## duplicate + +Derivable from `Extend`. **Signature** ```ts -export interface Writer { - (): readonly [A, W] -} +export declare const duplicate: (t: Writer) => Writer> +``` + +Added in v3.0.0 + +## extend + +**Signature** + +```ts +export declare const extend: (f: (wa: Writer) => B) => (wa: Writer) => Writer +``` + +Added in v3.0.0 + +## extract + +**Signature** + +```ts +export declare const extract: (wa: Writer) => A +``` + +Added in v3.0.0 + +## foldMap + +**Signature** + +```ts +export declare const foldMap: (M: Monoid) => (f: (a: A) => M) => (fa: Writer) => M +``` + +Added in v3.0.0 + +## map + +`map` can be used to turn functions `(a: A) => B` into functions `(fa: F) => F` whose argument and return types +use the type constructor `F` to represent some computational context. + +**Signature** + +```ts +export declare const map: (f: (a: A) => B) => (fa: Writer) => Writer +``` + +Added in v3.0.0 + +## mapLeft + +**Signature** + +```ts +export declare const mapLeft: (f: (e: E) => G) => (fea: Writer) => Writer +``` + +Added in v3.0.0 + +## reduce + +**Signature** + +```ts +export declare const reduce: (b: B, f: (b: B, a: A) => B) => (fa: Writer) => B +``` + +Added in v3.0.0 + +## reduceRight + +**Signature** + +```ts +export declare const reduceRight: (b: B, f: (a: A, b: B) => B) => (fa: Writer) => B +``` + +Added in v3.0.0 + +## traverse + +**Signature** + +```ts +export declare const traverse: Traverse2<'Writer'> ``` Added in v3.0.0 @@ -219,6 +423,8 @@ Added in v3.0.0 ## evaluate +Alias of [`fst`](#fst). + **Signature** ```ts @@ -229,6 +435,8 @@ Added in v3.0.0 ## execute +Alias of [`snd`](#snd). + **Signature** ```ts @@ -236,3 +444,51 @@ export declare const execute: (fa: Writer) => W ``` Added in v3.0.0 + +## fst + +**Signature** + +```ts +export declare const fst: (t: Writer) => A +``` + +Added in v3.0.0 + +## mapFst + +Maps a function over the first component of a `Writer`. + +Alias of [`map`](#map) + +**Signature** + +```ts +export declare const mapFst: (f: (a: A) => B) => (fa: Writer) => Writer +``` + +Added in v3.0.0 + +## mapSnd + +Maps a function over the second component of a `Writer`. + +Alias of [`mapLeft`](#mapleft) + +**Signature** + +```ts +export declare const mapSnd: (f: (e: E) => G) => (fea: Writer) => Writer +``` + +Added in v3.0.0 + +## snd + +**Signature** + +```ts +export declare const snd: (t: Writer) => W +``` + +Added in v3.0.0 diff --git a/docs/modules/WriterT.ts.md b/docs/modules/WriterT.ts.md new file mode 100644 index 000000000..6192dda38 --- /dev/null +++ b/docs/modules/WriterT.ts.md @@ -0,0 +1,587 @@ +--- +title: WriterT.ts +nav_order: 113 +parent: Modules +--- + +## WriterT overview + +Added in v3.0.0 + +--- + +

Table of contents

+ +- [combinators](#combinators) + - [censor](#censor) + - [listen](#listen) + - [listens](#listens) + - [pass](#pass) + - [swap](#swap) +- [constructors](#constructors) + - [fromF](#fromf) + - [fromIO](#fromio) + - [fromTask](#fromtask) + - [tell](#tell) +- [type class operations](#type-class-operations) + - [ap](#ap) + - [bimap](#bimap) + - [chain](#chain) + - [map](#map) + - [mapLeft](#mapleft) + - [of](#of) +- [utils](#utils) + - [fst](#fst) + - [snd](#snd) + +--- + +# combinators + +## censor + +Modify the final accumulator value by applying a function + +**Signature** + +```ts +export declare function censor( + F: Functor4 +): (f: (w: W) => W) => (fwa: Kind4>) => Kind4> +export declare function censor( + F: Functor3 +): (f: (w: W) => W) => (fwa: Kind3>) => Kind3> +export declare function censor( + F: Functor3C +): (f: (w: W) => W) => (fwa: Kind3>) => Kind3> +export declare function censor( + F: Functor2 +): (f: (w: W) => W) => (fwa: Kind2>) => Kind2> +export declare function censor( + F: Functor2C +): (f: (w: W) => W) =>
(fwa: Kind2>) => Kind2> +export declare function censor( + F: Functor1 +): (f: (w: W) => W) => (fwa: Kind>) => Kind> +export declare function censor( + F: Functor +): (f: (w: W) => W) => (fwa: HKT>) => HKT> +``` + +Added in v3.0.0 + +## listen + +Modifies the result to include the changes to the accumulator + +**Signature** + +```ts +export declare function listen( + F: Functor4 +): (fwa: Kind4>) => Kind4> +export declare function listen( + F: Functor3 +): (fwa: Kind3>) => Kind3> +export declare function listen( + F: Functor3C +): (fwa: Kind3>) => Kind3> +export declare function listen( + F: Functor2 +): (fwa: Kind2>) => Kind2> +export declare function listen( + F: Functor2C +): (fwa: Kind2>) => Kind2> +export declare function listen( + F: Functor1 +): (fwa: Kind>) => Kind> +export declare function listen( + F: Functor +): (fwa: HKT>) => HKT> +``` + +Added in v3.0.0 + +## listens + +Projects a value from modifications made to the accumulator during an action + +**Signature** + +```ts +export declare function listens( + F: Functor4 +): ( + f: (w: W) => B +) => (fwa: Kind4>) => Kind4> +export declare function listens( + F: Functor3 +): (f: (w: W) => B) => (fwa: Kind3>) => Kind3> +export declare function listens( + F: Functor3C +): (f: (w: W) => B) => (fwa: Kind3>) => Kind3> +export declare function listens( + F: Functor2 +): (f: (w: W) => B) => (fwa: Kind2>) => Kind2> +export declare function listens( + F: Functor2C +): (f: (w: W) => B) => (fwa: Kind2>) => Kind2> +export declare function listens( + F: Functor1 +): (f: (w: W) => B) => (fwa: Kind>) => Kind> +export declare function listens( + F: Functor +): (f: (w: W) => B) => (fwa: HKT>) => HKT> +``` + +Added in v3.0.0 + +## pass + +Applies the returned function to the accumulator + +**Signature** + +```ts +export declare function pass( + F: Functor4 +): (fwa: Kind4 W]>>) => Kind4> +export declare function pass( + F: Functor3 +): (fwa: Kind3 W]>>) => Kind3> +export declare function pass( + F: Functor3C +): (fwa: Kind3 W]>>) => Kind3> +export declare function pass( + F: Functor2 +): (fwa: Kind2 W]>>) => Kind2> +export declare function pass( + F: Functor2C +): (fwa: Kind2 W]>>) => Kind2> +export declare function pass( + F: Functor1 +): (fwa: Kind W]>>) => Kind> +export declare function pass( + F: Functor +): (fwa: HKT W]>>) => HKT> +``` + +Added in v3.0.0 + +## swap + +**Signature** + +```ts +export declare function swap( + F: Functor4 +): (fwa: Kind4>) => Kind4> +export declare function swap( + F: Functor3 +): (fwa: Kind3>) => Kind3> +export declare function swap( + F: Functor3C +): (fwa: Kind3>) => Kind3> +export declare function swap( + F: Functor2 +): (fwa: Kind2>) => Kind2> +export declare function swap( + F: Functor2C +): (fwa: Kind2>) => Kind2> +export declare function swap( + F: Functor1 +): (fwa: Kind>) => Kind> +export declare function swap(F: Functor): (fwa: HKT>) => HKT> +``` + +Added in v3.0.0 + +# constructors + +## fromF + +**Signature** + +```ts +export declare function fromF( + F: Functor4 +): (w: W) => (fa: Kind4) => Kind4> +export declare function fromF( + F: Functor3 +): (w: W) => (fa: Kind3) => Kind3> +export declare function fromF( + F: Functor3C +): (w: W) => (fa: Kind3) => Kind3> +export declare function fromF( + F: Functor2 +): (w: W) => (fa: Kind2) => Kind2> +export declare function fromF( + F: Functor2C +): (w: W) => (fa: Kind2) => Kind2> +export declare function fromF(F: Functor1): (w: W) => (fa: Kind) => Kind> +export declare function fromF(F: Functor): (w: W) => (fa: HKT) => HKT> +``` + +Added in v3.0.0 + +## fromIO + +**Signature** + +```ts +export declare function fromIO( + F: Functor4, + FT: FromIO4 +): (w: W) => (fa: IO) => Kind4> +export declare function fromIO( + F: Functor3, + FT: FromIO3 +): (w: W) => (fa: IO) => Kind3> +export declare function fromIO( + F: Functor3, + FT: FromIO3C +): (w: W) => (fa: IO) => Kind3> +export declare function fromIO( + F: Functor2, + FT: FromIO2 +): (w: W) => (fa: IO) => Kind2> +export declare function fromIO( + F: Functor2, + FT: FromIO2C +): (w: W) => (fa: IO) => Kind2> +export declare function fromIO( + F: Functor1, + FT: FromIO1 +): (w: W) => (fa: IO) => Kind> +export declare function fromIO(F: Functor, FT: FromIO): (w: W) => (fa: IO) => HKT> +``` + +Added in v3.0.0 + +## fromTask + +**Signature** + +```ts +export declare function fromTask( + F: Functor4, + FT: FromTask4 +): (w: W) => (fa: Task) => Kind4> +export declare function fromTask( + F: Functor3, + FT: FromTask3 +): (w: W) => (fa: Task) => Kind3> +export declare function fromTask( + F: Functor3, + FT: FromTask3C +): (w: W) => (fa: Task) => Kind3> +export declare function fromTask( + F: Functor2, + FT: FromTask2 +): (w: W) => (fa: Task) => Kind2> +export declare function fromTask( + F: Functor2, + FT: FromTask2C +): (w: W) => (fa: Task) => Kind2> +export declare function fromTask( + F: Functor1, + FT: FromTask1 +): (w: W) => (fa: Task) => Kind> +export declare function fromTask( + F: Functor, + FT: FromTask +): (w: W) => (fa: Task) => HKT> +``` + +Added in v3.0.0 + +## tell + +**Signature** + +```ts +export declare function tell(F: Pointed4): (w: W) => Kind4> +export declare function tell(F: Pointed3): (w: W) => Kind3> +export declare function tell(F: Pointed3C): (w: W) => Kind3> +export declare function tell(F: Pointed2): (w: W) => Kind2> +export declare function tell(F: Pointed2C): (w: W) => Kind2> +export declare function tell(F: Pointed1): (w: W) => Kind> +export declare function tell(F: Pointed): (w: W) => HKT> +``` + +Added in v3.0.0 + +# type class operations + +## ap + +**Signature** + +```ts +export declare function ap( + F: Apply4, + S: Semigroup +): ( + fa: Kind4> +) => (fab: Kind4 B>>) => Kind4> +export declare function ap( + F: Apply3, + S: Semigroup +): ( + fa: Kind3> +) => (fab: Kind3 B>>) => Kind3> +export declare function ap( + F: Apply3C, + S: Semigroup +): ( + fa: Kind3> +) => (fab: Kind3 B>>) => Kind3> +export declare function ap( + F: Apply2, + S: Semigroup +): (fa: Kind2>) => (fab: Kind2 B>>) => Kind2> +export declare function ap( + F: Apply2C, + S: Semigroup +): (fa: Kind2>) => (fab: Kind2 B>>) => Kind2> +export declare function ap( + F: Apply1, + S: Semigroup +): (fa: Kind>) => (fab: Kind B>>) => Kind> +export declare function ap( + F: Apply, + S: Semigroup +): (fa: HKT>) => (fab: HKT B>>) => HKT> +``` + +Added in v3.0.0 + +## bimap + +**Signature** + +```ts +export declare function bimap( + F: Functor4 +): ( + mapSnd: (w: W) => G, + mapFst: (a: A) => B +) => (fwa: Kind4>) => Kind4> +export declare function bimap( + F: Functor3 +): ( + mapSnd: (w: W) => G, + mapFst: (a: A) => B +) => (fwa: Kind3>) => Kind3> +export declare function bimap( + F: Functor3C +): ( + mapSnd: (w: W) => G, + mapFst: (a: A) => B +) => (fwa: Kind3>) => Kind3> +export declare function bimap( + F: Functor2 +): ( + mapSnd: (w: W) => G, + mapFst: (a: A) => B +) => (fwa: Kind2>) => Kind2> +export declare function bimap( + F: Functor2C +): ( + mapSnd: (w: W) => G, + mapFst: (a: A) => B +) => (fwa: Kind2>) => Kind2> +export declare function bimap( + F: Functor1 +): (mapSnd: (w: W) => G, mapFst: (a: A) => B) => (fwa: Kind>) => Kind> +export declare function bimap( + F: Functor +): (mapSnd: (w: W) => G, mapFst: (a: A) => B) => (fwa: HKT>) => HKT> +``` + +Added in v3.0.0 + +## chain + +**Signature** + +```ts +export declare function chain( + M: Chain4, + S: Semigroup +): ( + f: (a: A) => Kind4> +) => (ma: Kind4>) => Kind4> +export declare function chain( + M: Chain3, + S: Semigroup +): ( + f: (a: A) => Kind3> +) => (ma: Kind3>) => Kind3> +export declare function chain( + M: Chain3C, + S: Semigroup +): ( + f: (a: A) => Kind3> +) => (ma: Kind3>) => Kind3> +export declare function chain( + M: Chain2, + S: Semigroup +): (f: (a: A) => Kind2>) => (ma: Kind2>) => Kind2> +export declare function chain( + M: Chain2C, + S: Semigroup +): (f: (a: A) => Kind2>) => (ma: Kind2>) => Kind2> +export declare function chain( + M: Chain1, + S: Semigroup +): (f: (a: A) => Kind>) => (ma: Kind>) => Kind> +export declare function chain( + M: Chain, + S: Semigroup +): (f: (a: A) => HKT>) => (ma: HKT>) => HKT> +``` + +Added in v3.0.0 + +## map + +**Signature** + +```ts +export declare function map( + F: Functor4 +): (f: (a: A) => B) => (fa: Kind4>) => Kind4> +export declare function map( + F: Functor3 +): (f: (a: A) => B) => (fa: Kind3>) => Kind3> +export declare function map( + F: Functor3C +): (f: (a: A) => B) => (fa: Kind3>) => Kind3> +export declare function map( + F: Functor2 +): (f: (a: A) => B) => (fa: Kind2>) => Kind2> +export declare function map( + F: Functor2C +): (f: (a: A) => B) => (fa: Kind2>) => Kind2> +export declare function map( + F: Functor1 +): (f: (a: A) => B) => (fa: Kind>) => Kind> +export declare function map( + F: Functor +): (f: (a: A) => B) => (fa: HKT>) => HKT> +``` + +Added in v3.0.0 + +## mapLeft + +**Signature** + +```ts +export declare function mapLeft( + F: Functor4 +): (mapSnd: (w: W) => G) => (fwa: Kind4>) => Kind4> +export declare function mapLeft( + F: Functor3 +): (mapSnd: (w: W) => G) => (fwa: Kind3>) => Kind3> +export declare function mapLeft( + F: Functor3C +): (mapSnd: (w: W) => G) => (fwa: Kind3>) => Kind3> +export declare function mapLeft( + F: Functor2 +): (mapSnd: (w: W) => G) => (fwa: Kind2>) => Kind2> +export declare function mapLeft( + F: Functor2C +): (mapSnd: (w: W) => G) => (fwa: Kind2>) => Kind2> +export declare function mapLeft( + F: Functor1 +): (mapSnd: (w: W) => G) => (fwa: Kind>) => Kind> +export declare function mapLeft( + F: Functor +): (mapSnd: (w: W) => G) => (fwa: HKT>) => HKT> +``` + +Added in v3.0.0 + +## of + +**Signature** + +```ts +export declare function of( + F: Pointed4, + M: Monoid +): (a: A) => Kind4> +export declare function of( + F: Pointed3, + M: Monoid +): (a: A) => Kind3> +export declare function of( + F: Pointed3C, + M: Monoid +): (a: A) => Kind3> +export declare function of(F: Pointed2, M: Monoid): (a: A) => Kind2> +export declare function of( + F: Pointed2C, + M: Monoid +): (a: A) => Kind2> +export declare function of(F: Pointed1, M: Monoid): (a: A) => Kind> +export declare function of(F: Pointed, M: Monoid): (a: A) => HKT> +``` + +Added in v3.0.0 + +# utils + +## fst + +**Signature** + +```ts +export declare function fst( + F: Functor4 +): (fwa: Kind4>) => Kind4 +export declare function fst( + F: Functor3 +): (fwa: Kind3>) => Kind3 +export declare function fst( + F: Functor3C +): (fwa: Kind3>) => Kind3 +export declare function fst( + F: Functor2 +): (fwa: Kind2>) => Kind2 +export declare function fst( + F: Functor2C +): (fwa: Kind2>) => Kind2 +export declare function fst(F: Functor1): (fwa: Kind>) => Kind +export declare function fst(F: Functor): (fwa: HKT>) => HKT +``` + +Added in v3.0.0 + +## snd + +**Signature** + +```ts +export declare function snd( + F: Functor4 +): (fwa: Kind4>) => Kind4 +export declare function snd( + F: Functor3 +): (fwa: Kind3>) => Kind3 +export declare function snd( + F: Functor3C +): (fwa: Kind3>) => Kind3 +export declare function snd( + F: Functor2 +): (fwa: Kind2>) => Kind2 +export declare function snd( + F: Functor2C +): (fwa: Kind2>) => Kind2 +export declare function snd(F: Functor1): (fwa: Kind>) => Kind +export declare function snd(F: Functor): (fwa: HKT>) => HKT +``` + +Added in v3.0.0 diff --git a/docs/modules/Zero.ts.md b/docs/modules/Zero.ts.md index b1beada53..3c6623394 100644 --- a/docs/modules/Zero.ts.md +++ b/docs/modules/Zero.ts.md @@ -1,6 +1,6 @@ --- title: Zero.ts -nav_order: 112 +nav_order: 114 parent: Modules --- diff --git a/docs/modules/function.ts.md b/docs/modules/function.ts.md index ca502a33c..768d0f8f5 100644 --- a/docs/modules/function.ts.md +++ b/docs/modules/function.ts.md @@ -1,6 +1,6 @@ --- title: function.ts -nav_order: 40 +nav_order: 41 parent: Modules --- diff --git a/docs/modules/index.ts.md b/docs/modules/index.ts.md index 1a50872cd..d405056c1 100644 --- a/docs/modules/index.ts.md +++ b/docs/modules/index.ts.md @@ -1,6 +1,6 @@ --- title: index.ts -nav_order: 47 +nav_order: 48 parent: Modules --- @@ -52,6 +52,7 @@ Added in v3.0.0 - [fromState](#fromstate) - [fromTask](#fromtask) - [fromThese](#fromthese) + - [fromWriter](#fromwriter) - [function](#function) - [functor](#functor) - [functorWithIndex](#functorwithindex) @@ -87,6 +88,7 @@ Added in v3.0.0 - [readerT](#readert) - [readerTask](#readertask) - [readerTaskEither](#readertaskeither) + - [readerTaskWriter](#readertaskwriter) - [readonlyArray](#readonlyarray) - [readonlyMap](#readonlymap) - [readonlyNonEmptyArray](#readonlynonemptyarray) @@ -117,11 +119,11 @@ Added in v3.0.0 - [traversableWithIndex](#traversablewithindex) - [tree](#tree) - [tuple](#tuple) - - [tuple2](#tuple2) - [unfoldable](#unfoldable) - [void](#void) - [witherable](#witherable) - [writer](#writer) + - [writerT](#writert) - [zero](#zero) --- @@ -518,6 +520,16 @@ export declare const fromThese: typeof fromThese Added in v3.0.0 +## fromWriter + +**Signature** + +```ts +export declare const fromWriter: typeof fromWriter +``` + +Added in v3.0.0 + ## function **Signature** @@ -868,6 +880,16 @@ export declare const readerTaskEither: typeof readerTaskEither Added in v3.0.0 +## readerTaskWriter + +**Signature** + +```ts +export declare const readerTaskWriter: typeof readerTaskWriter +``` + +Added in v3.0.0 + ## readonlyArray **Signature** @@ -1168,16 +1190,6 @@ export declare const tuple: typeof tuple Added in v3.0.0 -## tuple2 - -**Signature** - -```ts -export declare const tuple2: typeof tuple2 -``` - -Added in v3.0.0 - ## unfoldable **Signature** @@ -1218,6 +1230,16 @@ export declare const writer: typeof writer Added in v3.0.0 +## writerT + +**Signature** + +```ts +export declare const writerT: typeof writerT +``` + +Added in v3.0.0 + ## zero **Signature** diff --git a/docs/modules/internal.ts.md b/docs/modules/internal.ts.md index d1984306a..e83992304 100644 --- a/docs/modules/internal.ts.md +++ b/docs/modules/internal.ts.md @@ -1,6 +1,6 @@ --- title: internal.ts -nav_order: 48 +nav_order: 49 parent: Modules --- diff --git a/docs/modules/number.ts.md b/docs/modules/number.ts.md index e1fee0c0a..1c75d7067 100644 --- a/docs/modules/number.ts.md +++ b/docs/modules/number.ts.md @@ -1,6 +1,6 @@ --- title: number.ts -nav_order: 62 +nav_order: 63 parent: Modules --- diff --git a/docs/modules/string.ts.md b/docs/modules/string.ts.md index 16f51ce33..96161641f 100644 --- a/docs/modules/string.ts.md +++ b/docs/modules/string.ts.md @@ -1,6 +1,6 @@ --- title: string.ts -nav_order: 93 +nav_order: 95 parent: Modules --- diff --git a/docs/modules/struct.ts.md b/docs/modules/struct.ts.md index 3c9f81460..602f0b1c9 100644 --- a/docs/modules/struct.ts.md +++ b/docs/modules/struct.ts.md @@ -1,6 +1,6 @@ --- title: struct.ts -nav_order: 95 +nav_order: 97 parent: Modules --- diff --git a/docs/modules/tuple.ts.md b/docs/modules/tuple.ts.md index a10624bab..0e2575b56 100644 --- a/docs/modules/tuple.ts.md +++ b/docs/modules/tuple.ts.md @@ -1,6 +1,6 @@ --- title: tuple.ts -nav_order: 106 +nav_order: 108 parent: Modules --- diff --git a/docs/modules/void.ts.md b/docs/modules/void.ts.md index 369ad4153..8e198dc84 100644 --- a/docs/modules/void.ts.md +++ b/docs/modules/void.ts.md @@ -1,6 +1,6 @@ --- title: void.ts -nav_order: 109 +nav_order: 110 parent: Modules --- diff --git a/src/Apply.ts b/src/Apply.ts index 33840c78f..7163f5153 100644 --- a/src/Apply.ts +++ b/src/Apply.ts @@ -115,19 +115,19 @@ export interface Apply4 extends Functor4 { export function ap( F: Apply4, G: Apply4 -): ( +): ( fa: Kind4> ) => (fab: Kind4 B>>) => Kind4> export function ap( F: Apply4, G: Apply3 -): ( +): ( fa: Kind4> ) => (fab: Kind4 B>>) => Kind4> export function ap( F: Apply4, G: Apply3C -): ( +): ( fa: Kind4> ) => (fab: Kind4 B>>) => Kind4> export function ap( @@ -148,37 +148,37 @@ export function ap( ): ( fa: Kind4> ) => (fab: Kind4 B>>) => Kind4> -export function ap( +export function ap( F: Apply3C, G: Apply4 -): ( +): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> -export function ap( +export function ap( F: Apply3C, G: Apply3 ): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> -export function ap( +export function ap( F: Apply3C, G: Apply3C -): ( +): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> -export function ap( +export function ap( F: Apply3C, G: Apply2 ): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> -export function ap( +export function ap( F: Apply3C, G: Apply2C ): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> -export function ap( +export function ap( F: Apply3C, G: Apply1 ): ( @@ -187,19 +187,19 @@ export function ap( export function ap( F: Apply3, G: Apply4 -): ( +): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> export function ap( F: Apply3, G: Apply3 -): ( +): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> export function ap( F: Apply3, G: Apply3C -): ( +): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> export function ap( @@ -220,56 +220,56 @@ export function ap( ): ( fa: Kind3> ) => (fab: Kind3 B>>) => Kind3> -export function ap( +export function ap( F: Apply2C, G: Apply4 ): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> -export function ap( +export function ap( F: Apply2C, G: Apply3 ): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> -export function ap( +export function ap( F: Apply2C, G: Apply3C ): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> -export function ap( +export function ap( F: Apply2C, G: Apply2 ): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> -export function ap( +export function ap( F: Apply2C, G: Apply2C ): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> -export function ap( +export function ap( F: Apply2C, G: Apply1 ): (fa: Kind2>) => (fab: Kind2 B>>) => Kind2> export function ap( F: Apply2, G: Apply4 -): ( +): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> export function ap( F: Apply2, G: Apply3 -): ( +): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> export function ap( F: Apply2, G: Apply3C -): ( +): ( fa: Kind2> ) => (fab: Kind2 B>>) => Kind2> export function ap( diff --git a/src/FromWriter.ts b/src/FromWriter.ts new file mode 100644 index 000000000..8a51bf69c --- /dev/null +++ b/src/FromWriter.ts @@ -0,0 +1,120 @@ +/** + * The `FromWriter` type class represents those data types which support accumulators. + * + * @since 3.0.0 + */ +import { flow } from './function' +import type { HKT2, Kind, Kind2, Kind3, Kind4, URIS, URIS2, URIS3, URIS4 } from './HKT' +import { + NaturalTransformation21, + NaturalTransformation22, + NaturalTransformation22C, + NaturalTransformation23, + NaturalTransformation23C, + NaturalTransformation24 +} from './NaturalTransformation' +import type { URI, Writer } from './Writer' + +// ------------------------------------------------------------------------------------- +// model +// ------------------------------------------------------------------------------------- + +/** + * @category type classes + * @since 3.0.0 + */ +export interface FromWriter { + readonly URI?: F + readonly fromWriter: (e: Writer) => HKT2 +} + +/** + * @category type classes + * @since 3.0.0 + */ +export interface FromWriter1 { + readonly URI?: F + readonly fromWriter: NaturalTransformation21 +} + +/** + * @category type classes + * @since 3.0.0 + */ +export interface FromWriter2 { + readonly URI?: F + readonly fromWriter: NaturalTransformation22 +} + +/** + * @category type classes + * @since 3.0.0 + */ +export interface FromWriter2C { + readonly URI?: F + readonly _E?: E + readonly fromWriter: NaturalTransformation22C +} + +/** + * @category type classes + * @since 3.0.0 + */ +export interface FromWriter3 { + readonly URI?: F + readonly fromWriter: NaturalTransformation23 +} + +/** + * @category type classes + * @since 3.0.0 + */ +export interface FromWriter3C { + readonly URI?: F + readonly _E?: E + readonly fromWriter: NaturalTransformation23C +} + +/** + * @category type classes + * @since 3.0.0 + */ +export interface FromWriter4 { + readonly URI?: F + readonly fromWriter: NaturalTransformation24 +} + +// ------------------------------------------------------------------------------------- +// combinators +// ------------------------------------------------------------------------------------- + +/** + * @category combinators + * @since 3.0.0 + */ +export function fromWriterK( + F: FromWriter4 +): , E, B>(f: (...a: A) => Writer) => (...a: A) => Kind4 +export function fromWriterK( + F: FromWriter3 +): , E, B>(f: (...a: A) => Writer) => (...a: A) => Kind3 +export function fromWriterK( + F: FromWriter3C +): , B>(f: (...a: A) => Writer) => (...a: A) => Kind3 +export function fromWriterK( + F: FromWriter2 +): , E, B>(f: (...a: A) => Writer) => (...a: A) => Kind2 +export function fromWriterK( + F: FromWriter2C +): , B>(f: (...a: A) => Writer) => (...a: A) => Kind2 +export function fromWriterK( + F: FromWriter1 +): , E, B>(f: (...a: A) => Writer) => (...a: A) => Kind +export function fromWriterK( + F: FromWriter +): , E, B>(f: (...a: A) => Writer) => (...a: A) => HKT2 +export function fromWriterK( + F: FromWriter +): , E, B>(f: (...a: A) => Writer) => (...a: A) => HKT2 { + return (f) => flow(f, F.fromWriter) +} diff --git a/src/ReaderIO.ts b/src/ReaderIO.ts index d6b2344fc..bbf8fc008 100644 --- a/src/ReaderIO.ts +++ b/src/ReaderIO.ts @@ -134,7 +134,7 @@ export const chain: ( * @category Monad * @since 3.0.0 */ -export const chainW: ( +export const chainW: ( f: (a: A) => ReaderIO ) => (ma: ReaderIO) => ReaderIO = chain as any @@ -289,7 +289,7 @@ export const chainFirst = /*#__PURE__*/ chainFirst_(Chain) * @category combinators * @since 3.0.0 */ -export const chainFirstW: ( +export const chainFirstW: ( f: (a: A) => ReaderIO ) => (ma: ReaderIO) => ReaderIO = chainFirst as any @@ -434,7 +434,7 @@ export const apS = /*#__PURE__*/ apS_(Apply) * * @since 3.0.0 */ -export const apSW: ( +export const apSW: ( name: Exclude, fb: ReaderIO ) => ( diff --git a/src/ReaderTaskWriter.ts b/src/ReaderTaskWriter.ts new file mode 100644 index 000000000..5aa8adc16 --- /dev/null +++ b/src/ReaderTaskWriter.ts @@ -0,0 +1,471 @@ +/** + * @since 3.0.0 + */ +import type { Applicative3C } from './Applicative' +import type { Apply2, Apply3C } from './Apply' +import type { Bifunctor3 } from './Bifunctor' +import type { Chain3C } from './Chain' +import type { FromIO3C } from './FromIO' +import type { FromReader3C } from './FromReader' +import type { FromTask3C } from './FromTask' +import { FromWriter3, fromWriterK as fromWriterK_ } from './FromWriter' +import { flow } from './function' +import { bindTo as bindTo_, flap as flap_, Functor3, tupled as tupled_ } from './Functor' +import type { IO } from './IO' +import type { Monad3C } from './Monad' +import type { Monoid } from './Monoid' +import type { Pointed3C } from './Pointed' +import type { Reader } from './Reader' +import * as R from './Reader' +import * as RT from './ReaderTask' +import type { Semigroup } from './Semigroup' +import type { Task } from './Task' +import * as T from './Task' +import type { Writer } from './Writer' +import * as WT from './WriterT' + +import ReaderTask = RT.ReaderTask + +// ------------------------------------------------------------------------------------- +// model +// ------------------------------------------------------------------------------------- + +/** + * @category model + * @since 3.0.0 + */ +export interface ReaderTaskWriter extends Reader>> {} + +// ------------------------------------------------------------------------------------- +// constructors +// ------------------------------------------------------------------------------------- + +/** + * @category constructors + * @since 3.0.0 + */ +export const fromReader = (w: W) => (fa: Reader): ReaderTaskWriter => + fromReaderTask(w)(RT.fromReader(fa)) + +/** + * @category constructors + * @since 3.0.0 + */ +export const fromReaderTask: ( + w: W +) => (a: ReaderTask) => ReaderTaskWriter = /*#__PURE__*/ WT.fromF(RT.Functor) + +/** + * @category constructors + * @since 3.0.0 + */ +export const fromTaskWriter: (a: Task>) => ReaderTaskWriter = /*#__PURE__*/ R.of + +/** + * @category constructors + * @since 3.0.0 + */ +export const fromIO: (w: W) => (fa: IO) => ReaderTaskWriter = /*#__PURE__*/ WT.fromIO( + RT.Functor, + RT.FromIO +) + +/** + * @category constructors + * @since 3.0.0 + */ +export const fromTask: (w: W) => (fa: Task) => ReaderTaskWriter = /*#__PURE__*/ WT.fromTask( + RT.Functor, + RT.FromTask +) + +/** + * Appends a value to the accumulator + * + * @category constructors + * @since 3.0.0 + */ +export const tell: (w: W) => ReaderTaskWriter = /*#__PURE__*/ WT.tell(RT.Pointed) + +/** + * Less strict version of [`asksReaderTaskWriter`](#asksreadertaskwriter). + * + * @category constructors + * @since 3.0.0 + */ +export const asksReaderTaskWriterW: ( + f: (r1: R1) => ReaderTaskWriter +) => ReaderTaskWriter = R.asksReaderW + +/** + * @category constructors + * @since 3.0.0 + */ +export const asksReaderTaskWriter: ( + f: (r: R) => ReaderTaskWriter +) => ReaderTaskWriter = asksReaderTaskWriterW + +// ------------------------------------------------------------------------------------- +// natural transformations +// ------------------------------------------------------------------------------------- + +/** + * @category natural transformations + * @since 3.0.0 + */ +export const fromWriter = (w: Writer): ReaderTaskWriter => RT.of(w) + +/** + * @category natural transformations + * @since 3.0.0 + */ +export const fromReaderWriter = (fa: Reader>): ReaderTaskWriter => flow(fa, T.of) + +// ------------------------------------------------------------------------------------- +// utils +// ------------------------------------------------------------------------------------- + +/** + * @since 3.0.0 + */ +export const fst: (t: ReaderTaskWriter) => ReaderTask = /*#__PURE__*/ WT.fst(RT.Functor) + +/** + * @since 3.0.0 + */ +export const snd: (t: ReaderTaskWriter) => ReaderTask = /*#__PURE__*/ WT.snd(RT.Functor) + +/** + * Alias of [`fst`](#fst). + * + * @since 3.0.0 + */ +export const evaluate = fst + +/** + * Alias of [`snd`](#snd). + * + * @since 3.0.0 + */ +export const execute = snd + +// ------------------------------------------------------------------------------------- +// combinators +// ------------------------------------------------------------------------------------- + +/** + * Changes the value of the local context during the execution of the action `ma` (similar to `Contravariant`'s + * `contramap`). + * + * @category combinators + * @since 3.0.0 + */ +export const local: ( + f: (r2: R2) => R1 +) => (ma: ReaderTaskWriter) => ReaderTaskWriter = R.local + +/** + * @since 3.0.0 + */ +export const swap: (t: ReaderTaskWriter) => ReaderTaskWriter = /*#__PURE__*/ WT.swap( + RT.Functor +) + +/** + * @category combinators + * @since 3.0.0 + */ +export const fromTaskWriterK = , W, B>( + f: (...a: A) => Task> +): ((...a: A) => ReaderTaskWriter) => (...a) => fromTaskWriter(f(...a)) + +/** + * @category combinators + * @since 3.0.0 + */ +export const fromReaderWriterK = , R, W, B>( + f: (...a: A) => Reader> +): ((...a: A) => ReaderTaskWriter) => flow(f, fromReaderWriter) + +/** + * @since 3.0.0 + */ +export const listen: ( + fwa: ReaderTaskWriter +) => ReaderTaskWriter = /*#__PURE__*/ WT.listen(RT.Functor) + +/** + * @since 3.0.0 + */ +export const pass: ( + fwa: ReaderTaskWriter W]> +) => ReaderTaskWriter = /*#__PURE__*/ WT.pass(RT.Functor) + +/** + * @since 3.0.0 + */ +export const listens: ( + f: (w: W) => B +) => (fwa: ReaderTaskWriter) => ReaderTaskWriter = /*#__PURE__*/ WT.listens( + RT.Functor +) + +/** + * @since 3.0.0 + */ +export const censor: ( + f: (w: W) => W +) => (fwa: ReaderTaskWriter) => ReaderTaskWriter = /*#__PURE__*/ WT.censor(RT.Functor) + +// ------------------------------------------------------------------------------------- +// type class operations +// ------------------------------------------------------------------------------------- + +/** + * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F) => F` whose argument and return types + * use the type constructor `F` to represent some computational context. + * + * @category type class operations + * @since 3.0.0 + */ +export const map: Functor3['map'] = /*#__PURE__*/ WT.map(RT.Functor) + +/** + * @category type class operations + * @since 3.0.0 + */ +export const mapLeft: Bifunctor3['mapLeft'] = /*#__PURE__*/ WT.mapLeft(RT.Functor) + +/** + * Map a pair of functions over the two type arguments of the bifunctor. + * + * @category type class operations + * @since 3.0.0 + */ +export const bimap: Bifunctor3['bimap'] = /*#__PURE__*/ WT.bimap(RT.Functor) + +/** + * Maps a function over the first component of a `Writer`. + * + * Alias of [`map`](#map) + * + * @since 3.0.0 + */ +export const mapFst: Functor3['map'] = map + +/** + * Maps a function over the second component of a `Writer`. + * + * Alias of [`mapLeft`](#mapleft) + * + * @since 3.0.0 + */ +export const mapSnd: Bifunctor3['mapLeft'] = mapLeft + +// ------------------------------------------------------------------------------------- +// instances +// ------------------------------------------------------------------------------------- + +/** + * @category instances + * @since 3.0.0 + */ +export type URI = 'ReaderTaskWriter' + +declare module './HKT' { + interface URItoKind3 { + readonly ReaderTaskWriter: ReaderTaskWriter + } +} + +/** + * @category instances + * @since 3.0.0 + */ +export const Bifunctor: Bifunctor3 = { + bimap, + mapLeft: mapSnd +} + +/** + * @category instances + * @since 3.0.0 + */ +export const Functor: Functor3 = { + map +} + +/** + * Derivable from `Functor`. + * + * @category combinators + * @since 3.0.0 + */ +export const flap = /*#__PURE__*/ flap_(Functor) + +/** + * @category instances + * @since 3.0.0 + */ +export const getPointed = (M: Monoid): Pointed3C => ({ + of: WT.of(RT.Pointed, M) +}) + +/** + * @category instances + * @since 3.0.0 + */ +export const getApply = (A: Apply2, S: Semigroup): Apply3C => ({ + map, + ap: WT.ap(A, S) +}) + +/** + * @category instances + * @since 3.0.0 + */ +export const getApplicative = (A: Apply2, M: Monoid): Applicative3C => { + const { ap } = getApply(A, M) + const P = getPointed(M) + return { + map, + ap, + of: P.of + } +} + +/** + * @category instances + * @since 3.0.0 + */ +export const getChain = (S: Semigroup): Chain3C => { + return { + map, + chain: WT.chain(RT.Chain, S) + } +} + +/** + * @category instances + * @since 3.0.0 + */ +export const getMonad = (M: Monoid): Monad3C => { + const P = getPointed(M) + const C = getChain(M) + return { + map, + of: P.of, + chain: C.chain + } +} + +/** + * @category instances + * @since 3.0.0 + */ +export const FromWriter: FromWriter3 = { + fromWriter +} + +/** + * @category combinators + * @since 3.0.0 + */ +export const fromWriterK = /*#__PURE__*/ fromWriterK_(FromWriter) + +/** + * @category instances + * @since 3.0.0 + */ +export const getFromReader = (M: Monoid): FromReader3C => ({ + fromReader: fromReader(M.empty) +}) + +/** + * @category instances + * @since 3.0.0 + */ +export const getFromIO = (M: Monoid): FromIO3C => ({ + fromIO: fromIO(M.empty) +}) + +/** + * @category instances + * @since 3.0.0 + */ +export const getFromTask = (M: Monoid): FromTask3C => ({ + fromIO: fromIO(M.empty), + fromTask: fromTask(M.empty) +}) + +// ------------------------------------------------------------------------------------- +// do notation +// ------------------------------------------------------------------------------------- + +/** + * @since 3.0.0 + */ +export const bindTo = + /*#__PURE__*/ + bindTo_(Functor) + +// ------------------------------------------------------------------------------------- +// sequence T +// ------------------------------------------------------------------------------------- + +/** + * @since 3.0.0 + */ +export const tupled = + /*#__PURE__*/ + tupled_(Functor) + +// ------------------------------------------------------------------------------------- +// array utils +// ------------------------------------------------------------------------------------- + +// TODO + +// /** +// * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(ApplicativePar)`. +// * +// * @since 3.0.0 +// */ +// export const traverseReadonlyNonEmptyArrayWithIndex = ( +// f: (index: number, a: A) => ReaderTaskWriter +// ): ((as: ReadonlyNonEmptyArray) => ReaderTaskWriter>) => +// flow(R.traverseReadonlyNonEmptyArrayWithIndex(f), R.map(TE.traverseReadonlyNonEmptyArrayWithIndex(SK))) + +// /** +// * Equivalent to `ReadonlyArray#traverseWithIndex(ApplicativePar)`. +// * +// * @since 3.0.0 +// */ +// export const traverseReadonlyArrayWithIndex = ( +// f: (index: number, a: A) => ReaderTaskWriter +// ): ((as: ReadonlyArray) => ReaderTaskWriter>) => { +// const g = traverseReadonlyNonEmptyArrayWithIndex(f) +// return (as) => (_.isNonEmpty(as) ? g(as) : ApT) +// } + +// /** +// * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(ApplicativeSeq)`. +// * +// * @since 3.0.0 +// */ +// export const traverseReadonlyNonEmptyArrayWithIndexSeq = ( +// f: (index: number, a: A) => ReaderTaskWriter +// ): ((as: ReadonlyNonEmptyArray) => ReaderTaskWriter>) => +// flow(R.traverseReadonlyNonEmptyArrayWithIndex(f), R.map(TE.traverseReadonlyNonEmptyArrayWithIndexSeq(SK))) + +// /** +// * Equivalent to `ReadonlyArray#traverseWithIndex(ApplicativeSeq)`. +// * +// * @since 3.0.0 +// */ +// export const traverseReadonlyArrayWithIndexSeq = ( +// f: (index: number, a: A) => ReaderTaskWriter +// ): ((as: ReadonlyArray) => ReaderTaskWriter>) => { +// const g = traverseReadonlyNonEmptyArrayWithIndexSeq(f) +// return (as) => (_.isNonEmpty(as) ? g(as) : ApT) +// } diff --git a/src/ReadonlyMap.ts b/src/ReadonlyMap.ts index 7dce93a26..2ef4a2a76 100644 --- a/src/ReadonlyMap.ts +++ b/src/ReadonlyMap.ts @@ -25,7 +25,7 @@ import { separated, Separated } from './Separated' import type { Show } from './Show' import type { Traversable2C } from './Traversable' import type { TraversableWithIndex2C } from './TraversableWithIndex' -import { snd } from './Tuple2' +import { snd } from './Writer' import type { Unfoldable, Unfoldable1 } from './Unfoldable' import { wiltDefault, Witherable2C, witherDefault } from './Witherable' diff --git a/src/StateT.ts b/src/StateT.ts index da83b4cce..e33672a7e 100644 --- a/src/StateT.ts +++ b/src/StateT.ts @@ -7,7 +7,7 @@ import type { Functor, Functor1, Functor2, Functor2C, Functor3, Functor3C } from import type { HKT, Kind, Kind2, Kind3, URIS, URIS2, URIS3 } from './HKT' import type { Pointed, Pointed1, Pointed2, Pointed2C, Pointed3, Pointed3C } from './Pointed' import type { State } from './State' -import { snd } from './Tuple2' +import { snd } from './Writer' /** * @since 3.0.0 diff --git a/src/Tuple2.ts b/src/Tuple2.ts deleted file mode 100644 index ded38d537..000000000 --- a/src/Tuple2.ts +++ /dev/null @@ -1,321 +0,0 @@ -/** - * @since 3.0.0 - */ -import type { Applicative, Applicative2C } from './Applicative' -import type { Apply2C } from './Apply' -import { Bifunctor2, mapDefault, mapLeftDefault } from './Bifunctor' -import type { Chain2C } from './Chain' -import type { ChainRec2C } from './ChainRec' -import type { Comonad2 } from './Comonad' -import type { Either } from './Either' -import type { Extend2 } from './Extend' -import type { Foldable2 } from './Foldable' -import { identity, pipe } from './function' -import { flap as flap_, Functor2 } from './Functor' -import type { HKT } from './HKT' -import type { Monad2C } from './Monad' -import type { Monoid } from './Monoid' -import type { Pointed2C } from './Pointed' -import type { Semigroup } from './Semigroup' -import type { Semigroupoid2 } from './Semigroupoid' -import type { Traversable2 } from './Traversable' -import * as _ from './internal' - -// ------------------------------------------------------------------------------------- -// model -// ------------------------------------------------------------------------------------- - -/** - * @since 3.0.0 - */ -export type Tuple2 = readonly [A, E] - -// ------------------------------------------------------------------------------------- -// constructors -// ------------------------------------------------------------------------------------- - -/** - * @since 3.0.0 - */ -export const tuple2 = (a: A, e: E): Tuple2 => [a, e] - -// ------------------------------------------------------------------------------------- -// utils -// ------------------------------------------------------------------------------------- - -/** - * @since 3.0.0 - */ -export const fst = (t: Tuple2): A => t[0] - -/** - * @since 3.0.0 - */ -export const snd = (t: Tuple2): E => t[1] - -// ------------------------------------------------------------------------------------- -// combinators -// ------------------------------------------------------------------------------------- - -/** - * @category combinators - * @since 3.0.0 - */ -export const swap = (t: Tuple2): Tuple2 => [snd(t), fst(t)] - -// ------------------------------------------------------------------------------------- -// type class members -// ------------------------------------------------------------------------------------- - -/** - * Map a pair of functions over the two type arguments of the bifunctor. - * - * @category Bifunctor - * @since 3.0.0 - */ -export const bimap = (mapSnd: (e: E) => G, mapFst: (a: A) => B) => (t: Tuple2): Tuple2 => [ - mapFst(fst(t)), - mapSnd(snd(t)) -] - -/** - * Map a function over the second component of a `Tuple2`. - * - * This is the `mapLeft` operation of the `Bifunctor` instance. - * - * @category Bifunctor - * @since 3.0.0 - */ -export const mapSnd: Bifunctor2['mapLeft'] = - /*#__PURE__*/ - mapLeftDefault(bimap) - -/** - * @category Semigroupoid - * @since 3.0.0 - */ -export const compose: Semigroupoid2['compose'] = (bc) => (ab) => [fst(bc), snd(ab)] - -/** - * @category Extend - * @since 3.0.0 - */ -export const extend: Extend2['extend'] = (f) => (wa) => [f(wa), snd(wa)] - -/** - * @category Extract - * @since 3.0.0 - */ -export const extract: Comonad2['extract'] = fst - -/** - * Derivable from `Extend`. - * - * @category derivable combinators - * @since 3.0.0 - */ -export const duplicate: (t: Tuple2) => Tuple2> = - /*#__PURE__*/ - extend(identity) - -/** - * @category Foldable - * @since 3.0.0 - */ -export const reduce: Foldable2['reduce'] = (b, f) => (fa) => f(b, fst(fa)) - -/** - * @category Foldable - * @since 3.0.0 - */ -export const foldMap: Foldable2['foldMap'] = () => (f) => (fa) => f(fst(fa)) - -/** - * @category Foldable - * @since 3.0.0 - */ -export const reduceRight: Foldable2['reduceRight'] = (b, f) => (fa) => f(fst(fa), b) - -/** - * @since 3.0.0 - */ -export const traverse: Traversable2['traverse'] = (F: Applicative) => (f: (a: A) => HKT) => ( - t: Tuple2 -): HKT> => - pipe( - f(fst(t)), - F.map((b) => [b, snd(t)]) - ) - -// ------------------------------------------------------------------------------------- -// instances -// ------------------------------------------------------------------------------------- - -/** - * @category instances - * @since 3.0.0 - */ -export type URI = 'Tuple2' - -declare module './HKT' { - interface URItoKind2 { - readonly Tuple2: Tuple2 - } -} - -/** - * @category instances - * @since 3.0.0 - */ -export const Bifunctor: Bifunctor2 = { - bimap, - mapLeft: mapSnd -} - -/** - * Map a function over the first component of a `Tuple2`. - * - * This is the `map` operation of the `Functor` instance. - * - * @category Functor - * @since 3.0.0 - */ -export const mapFst: Functor2['map'] = - /*#__PURE__*/ - mapDefault(Bifunctor) - -/** - * @category instances - * @since 3.0.0 - */ -export const Functor: Functor2 = { - map: mapFst -} - -/** - * Derivable from `Functor`. - * - * @category combinators - * @since 3.0.0 - */ -export const flap = - /*#__PURE__*/ - flap_(Functor) - -/** - * @category instances - * @since 3.0.0 - */ -export const Semigroupoid: Semigroupoid2 = { - compose -} - -/** - * @category instances - * @since 3.0.0 - */ -export const Comonad: Comonad2 = { - map: mapFst, - extend, - extract -} - -/** - * @category instances - * @since 3.0.0 - */ -export const Foldable: Foldable2 = { - reduce, - foldMap, - reduceRight -} - -/** - * @category instances - * @since 3.0.0 - */ -export const Traversable: Traversable2 = { - map: mapFst, - traverse -} - -/** - * @category instances - * @since 3.0.0 - */ -export const getPointed = (M: Monoid): Pointed2C => ({ - of: (a) => [a, M.empty] -}) - -/** - * @category instances - * @since 3.0.0 - */ -export const getApply = (S: Semigroup): Apply2C => ({ - map: mapFst, - ap: (fa) => (fab) => [fst(fab)(fst(fa)), S.concat(snd(fa))(snd(fab))] -}) - -/** - * @category instances - * @since 3.0.0 - */ -export const getApplicative = (M: Monoid): Applicative2C => { - const A = getApply(M) - const P = getPointed(M) - return { - map: mapFst, - ap: A.ap, - of: P.of - } -} - -/** - * @category instances - * @since 3.0.0 - */ -export const getChain = (S: Semigroup): Chain2C => { - return { - map: mapFst, - chain: (f) => (ma) => { - const [b, s] = f(fst(ma)) - return [b, S.concat(s)(snd(ma))] - } - } -} - -/** - * @category instances - * @since 3.0.0 - */ -export const getMonad = (M: Monoid): Monad2C => { - const P = getPointed(M) - const C = getChain(M) - return { - map: mapFst, - chain: C.chain, - of: P.of - } -} - -/** - * @category instances - * @since 3.0.0 - */ -export function getChainRec(M: Monoid): ChainRec2C { - const chainRec = (f: (a: A) => readonly [Either, M]) => (a: A): readonly [B, M] => { - let result: readonly [Either, M] = f(a) - let acc: M = M.empty - let s: Either = fst(result) - while (_.isLeft(s)) { - acc = M.concat(snd(result))(acc) - result = f(s.left) - s = fst(result) - } - return [s.right, M.concat(snd(result))(acc)] - } - - return { - chainRec - } -} diff --git a/src/Writer.ts b/src/Writer.ts index 90abd18af..c11c30024 100644 --- a/src/Writer.ts +++ b/src/Writer.ts @@ -1,14 +1,25 @@ /** * @since 3.0.0 */ -import type { Applicative2C } from './Applicative' +import type { Applicative, Applicative2C } from './Applicative' import type { Apply2C } from './Apply' +import { Bifunctor2 } from './Bifunctor' import type { Chain2C } from './Chain' +import type { ChainRec2C } from './ChainRec' +import type { Comonad2 } from './Comonad' +import type { Either } from './Either' +import type { Extend2 } from './Extend' +import type { Foldable2 } from './Foldable' +import { identity, pipe } from './function' import { flap as flap_, Functor2 } from './Functor' +import type { HKT } from './HKT' +import * as _ from './internal' import type { Monad2C } from './Monad' import type { Monoid } from './Monoid' import type { Pointed2C } from './Pointed' import type { Semigroup } from './Semigroup' +import type { Semigroupoid2 } from './Semigroupoid' +import type { Traversable2 } from './Traversable' // ------------------------------------------------------------------------------------- // model @@ -18,34 +29,72 @@ import type { Semigroup } from './Semigroup' * @category model * @since 3.0.0 */ -export interface Writer { - (): readonly [A, W] -} +export type Writer = readonly [A, W] // ------------------------------------------------------------------------------------- // constructors // ------------------------------------------------------------------------------------- +/** + * @category constructors + * @since 3.0.0 + */ +export const fromIdentity = (w: W) => (a: A): Writer => [a, w] + /** * Appends a value to the accumulator * * @category constructors * @since 3.0.0 */ -export const tell: (w: W) => Writer = (w) => () => [undefined, w] +export const tell: (w: W) => Writer = (w) => [undefined, w] + +// ------------------------------------------------------------------------------------- +// utils +// ------------------------------------------------------------------------------------- + +/** + * @since 3.0.0 + */ +export const fst = (t: Writer): A => t[0] + +/** + * @since 3.0.0 + */ +export const snd = (t: Writer): W => t[1] + +/** + * Alias of [`fst`](#fst). + * + * @since 3.0.0 + */ +export const evaluate: (fa: Writer) => A = fst + +/** + * Alias of [`snd`](#snd). + * + * @since 3.0.0 + */ +export const execute: (fa: Writer) => W = snd // ------------------------------------------------------------------------------------- // combinators // ------------------------------------------------------------------------------------- +/** + * @category combinators + * @since 3.0.0 + */ +export const swap = (t: Writer): Writer => [snd(t), fst(t)] + /** * Modifies the result to include the changes to the accumulator * * @category combinators * @since 3.0.0 */ -export const listen: (fa: Writer) => Writer = (fa) => () => { - const [a, w] = fa() +export const listen: (fa: Writer) => Writer = (fa) => { + const [a, w] = fa return [[a, w], w] } @@ -55,8 +104,8 @@ export const listen: (fa: Writer) => Writer = (f * @category combinators * @since 3.0.0 */ -export const pass: (fa: Writer W]>) => Writer = (fa) => () => { - const [[a, f], w] = fa() +export const pass: (fa: Writer W]>) => Writer = (fa) => { + const [[a, f], w] = fa return [a, f(w)] } @@ -66,10 +115,8 @@ export const pass: (fa: Writer W]>) => Writer(f: (w: W) => B) => (fa: Writer) => Writer = (f) => ( - fa -) => () => { - const [a, w] = fa() +export const listens: (f: (w: W) => B) => (fa: Writer) => Writer = (f) => (fa) => { + const [a, w] = fa return [[a, f(w)], w] } @@ -79,27 +126,121 @@ export const listens: (f: (w: W) => B) => (fa: Writer) => Writer< * @category combinators * @since 3.0.0 */ -export const censor: (f: (w: W) => W) => (fa: Writer) => Writer = (f) => (fa) => () => { - const [a, w] = fa() +export const censor: (f: (w: W) => W) => (fa: Writer) => Writer = (f) => (fa) => { + const [a, w] = fa return [a, f(w)] } // ------------------------------------------------------------------------------------- -// type class members +// type class operations // ------------------------------------------------------------------------------------- /** * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F) => F` whose argument and return types * use the type constructor `F` to represent some computational context. * - * @category Functor + * @category type class operations * @since 3.0.0 */ -export const map: Functor2['map'] = (f) => (fa) => () => { - const [a, w] = fa() +export const map: Functor2['map'] = (f) => (fa) => { + const [a, w] = fa return [f(a), w] } +/** + * @category type class operations + * @since 3.0.0 + */ +export const mapLeft: Bifunctor2['mapLeft'] = (f) => (fa) => { + const [a, w] = fa + return [a, f(w)] +} + +/** + * Map a pair of functions over the two type arguments of the bifunctor. + * + * @category type class operations + * @since 3.0.0 + */ +export const bimap = (mapSnd: (e: W) => G, mapFst: (a: A) => B) => (t: Writer): Writer => [ + mapFst(fst(t)), + mapSnd(snd(t)) +] + +/** + * Maps a function over the first component of a `Writer`. + * + * Alias of [`map`](#map) + * + * @since 3.0.0 + */ +export const mapFst: Functor2['map'] = map + +/** + * Maps a function over the second component of a `Writer`. + * + * Alias of [`mapLeft`](#mapleft) + * + * @since 3.0.0 + */ +export const mapSnd: Bifunctor2['mapLeft'] = mapLeft + +/** + * @category type class operations + * @since 3.0.0 + */ +export const compose: Semigroupoid2['compose'] = (bc) => (ab) => [fst(bc), snd(ab)] + +/** + * @category type class operations + * @since 3.0.0 + */ +export const extend: Extend2['extend'] = (f) => (wa) => [f(wa), snd(wa)] + +/** + * @category type class operations + * @since 3.0.0 + */ +export const extract: Comonad2['extract'] = fst + +/** + * Derivable from `Extend`. + * + * @category type class operations + * @since 3.0.0 + */ +export const duplicate: (t: Writer) => Writer> = /*#__PURE__*/ extend(identity) + +/** + * @category type class operations + * @since 3.0.0 + */ +export const reduce: Foldable2['reduce'] = (b, f) => (fa) => f(b, fst(fa)) + +/** + * @category type class operations + * @since 3.0.0 + */ +export const foldMap: Foldable2['foldMap'] = () => (f) => (fa) => f(fst(fa)) + +/** + * @category type class operations + * @since 3.0.0 + */ +export const reduceRight: Foldable2['reduceRight'] = (b, f) => (fa) => f(fst(fa), b) + +/** + * @category type class operations + * @since 3.0.0 + */ +export const traverse: Traversable2['traverse'] = (F: Applicative) => (f: (a: A) => HKT) => ( + t: Writer +): HKT> => + pipe( + f(fst(t)), + F.map((b) => [b, snd(t)]) + ) + // ------------------------------------------------------------------------------------- // instances // ------------------------------------------------------------------------------------- @@ -116,12 +257,74 @@ declare module './HKT' { } } +/** + * @category instances + * @since 3.0.0 + */ +export const Bifunctor: Bifunctor2 = { + bimap, + mapLeft: mapSnd +} + +/** + * @category instances + * @since 3.0.0 + */ +export const Functor: Functor2 = { + map: mapFst +} + +/** + * Derivable from `Functor`. + * + * @category combinators + * @since 3.0.0 + */ +export const flap = /*#__PURE__*/ flap_(Functor) + +/** + * @category instances + * @since 3.0.0 + */ +export const Semigroupoid: Semigroupoid2 = { + compose +} + +/** + * @category instances + * @since 3.0.0 + */ +export const Comonad: Comonad2 = { + map: mapFst, + extend, + extract +} + +/** + * @category instances + * @since 3.0.0 + */ +export const Foldable: Foldable2 = { + reduce, + foldMap, + reduceRight +} + +/** + * @category instances + * @since 3.0.0 + */ +export const Traversable: Traversable2 = { + map: mapFst, + traverse +} + /** * @category instances * @since 3.0.0 */ export const getPointed = (M: Monoid): Pointed2C => ({ - of: (a) => () => [a, M.empty] + of: (a) => [a, M.empty] }) /** @@ -130,9 +333,9 @@ export const getPointed = (M: Monoid): Pointed2C => ({ */ export const getApply = (S: Semigroup): Apply2C => ({ map, - ap: (fa) => (fab) => () => { - const [f, w1] = fab() - const [a, w2] = fa() + ap: (fa) => (fab) => { + const [f, w1] = fab + const [a, w2] = fa return [f(a), S.concat(w2)(w1)] } }) @@ -158,9 +361,9 @@ export const getApplicative = (M: Monoid): Applicative2C => { export const getChain = (S: Semigroup): Chain2C => { return { map, - chain: (f) => (ma) => () => { - const [a, w1] = ma() - const [b, w2] = f(a)() + chain: (f) => (ma) => { + const [a, w1] = ma + const [b, w2] = f(a) return [b, S.concat(w2)(w1)] } } @@ -184,30 +387,20 @@ export const getMonad = (M: Monoid): Monad2C => { * @category instances * @since 3.0.0 */ -export const Functor: Functor2 = { - map -} - -/** - * Derivable from `Functor`. - * - * @category combinators - * @since 3.0.0 - */ -export const flap = - /*#__PURE__*/ - flap_(Functor) - -// ------------------------------------------------------------------------------------- -// utils -// ------------------------------------------------------------------------------------- - -/** - * @since 3.0.0 - */ -export const evaluate: (fa: Writer) => A = (fa) => fa()[0] +export function getChainRec(M: Monoid): ChainRec2C { + const chainRec = (f: (a: A) => readonly [Either, M]) => (a: A): readonly [B, M] => { + let result: readonly [Either, M] = f(a) + let acc: M = M.empty + let s: Either = fst(result) + while (_.isLeft(s)) { + acc = M.concat(snd(result))(acc) + result = f(s.left) + s = fst(result) + } + return [s.right, M.concat(snd(result))(acc)] + } -/** - * @since 3.0.0 - */ -export const execute: (fa: Writer) => W = (fa) => fa()[1] + return { + chainRec + } +} diff --git a/src/WriterT.ts b/src/WriterT.ts new file mode 100644 index 000000000..3d04f2c3d --- /dev/null +++ b/src/WriterT.ts @@ -0,0 +1,556 @@ +/** + * @since 3.0.0 + */ +import { ap as ap_, Apply, Apply1, Apply2, Apply2C, Apply3, Apply3C, Apply4 } from './Apply' +import type { Chain, Chain1, Chain2, Chain2C, Chain3, Chain3C, Chain4 } from './Chain' +import type { FromIO, FromIO1, FromIO2, FromIO2C, FromIO3, FromIO3C, FromIO4 } from './FromIO' +import type { FromTask, FromTask1, FromTask2, FromTask2C, FromTask3, FromTask3C, FromTask4 } from './FromTask' +import { flow, pipe } from './function' +import { Functor, Functor1, Functor2, Functor2C, Functor3, Functor3C, Functor4, map as map_ } from './Functor' +import type { HKT, Kind, Kind2, Kind3, Kind4, URIS, URIS2, URIS3, URIS4 } from './HKT' +import type { IO } from './IO' +import type { Monoid } from './Monoid' +import type { Pointed, Pointed1, Pointed2, Pointed2C, Pointed3, Pointed3C, Pointed4 } from './Pointed' +import type { Semigroup } from './Semigroup' +import type { Task } from './Task' +import * as W from './Writer' + +import Writer = W.Writer + +// ------------------------------------------------------------------------------------- +// constructors +// ------------------------------------------------------------------------------------- + +/** + * @category constructors + * @since 3.0.0 + */ +export function fromF( + F: Functor4 +): (w: W) => (fa: Kind4) => Kind4> +export function fromF( + F: Functor3 +): (w: W) => (fa: Kind3) => Kind3> +export function fromF( + F: Functor3C +): (w: W) => (fa: Kind3) => Kind3> +export function fromF( + F: Functor2 +): (w: W) => (fa: Kind2) => Kind2> +export function fromF( + F: Functor2C +): (w: W) => (fa: Kind2) => Kind2> +export function fromF(F: Functor1): (w: W) => (fa: Kind) => Kind> +export function fromF(F: Functor): (w: W) => (fa: HKT) => HKT> +export function fromF(F: Functor): (w: W) => (fa: HKT) => HKT> { + return (w) => F.map(W.fromIdentity(w)) +} + +/** + * @category constructors + * @since 3.0.0 + */ +export function fromIO( + F: Functor4, + FT: FromIO4 +): (w: W) => (fa: IO) => Kind4> +export function fromIO( + F: Functor3, + FT: FromIO3 +): (w: W) => (fa: IO) => Kind3> +export function fromIO( + F: Functor3, + FT: FromIO3C +): (w: W) => (fa: IO) => Kind3> +export function fromIO( + F: Functor2, + FT: FromIO2 +): (w: W) => (fa: IO) => Kind2> +export function fromIO( + F: Functor2, + FT: FromIO2C +): (w: W) => (fa: IO) => Kind2> +export function fromIO( + F: Functor1, + FT: FromIO1 +): (w: W) => (fa: IO) => Kind> +export function fromIO(F: Functor, FT: FromIO): (w: W) => (fa: IO) => HKT> +export function fromIO(F: Functor, FT: FromIO): (w: W) => (fa: IO) => HKT> { + return (w) => flow(FT.fromIO, F.map(W.fromIdentity(w))) +} + +/** + * @category constructors + * @since 3.0.0 + */ +export function fromTask( + F: Functor4, + FT: FromTask4 +): (w: W) => (fa: Task) => Kind4> +export function fromTask( + F: Functor3, + FT: FromTask3 +): (w: W) => (fa: Task) => Kind3> +export function fromTask( + F: Functor3, + FT: FromTask3C +): (w: W) => (fa: Task) => Kind3> +export function fromTask( + F: Functor2, + FT: FromTask2 +): (w: W) => (fa: Task) => Kind2> +export function fromTask( + F: Functor2, + FT: FromTask2C +): (w: W) => (fa: Task) => Kind2> +export function fromTask( + F: Functor1, + FT: FromTask1 +): (w: W) => (fa: Task) => Kind> +export function fromTask(F: Functor, FT: FromTask): (w: W) => (fa: Task) => HKT> +export function fromTask(F: Functor, FT: FromTask): (w: W) => (fa: Task) => HKT> { + return (w) => flow(FT.fromTask, F.map(W.fromIdentity(w))) +} + +/** + * @category constructors + * @since 3.0.0 + */ +export function tell(F: Pointed4): (w: W) => Kind4> +export function tell(F: Pointed3): (w: W) => Kind3> +export function tell(F: Pointed3C): (w: W) => Kind3> +export function tell(F: Pointed2): (w: W) => Kind2> +export function tell(F: Pointed2C): (w: W) => Kind2> +export function tell(F: Pointed1): (w: W) => Kind> +export function tell(F: Pointed): (w: W) => HKT> +export function tell(F: Pointed): (w: W) => HKT> { + return flow(W.tell, F.of) +} + +// ------------------------------------------------------------------------------------- +// type class operations +// ------------------------------------------------------------------------------------- + +/** + * @category type class operations + * @since 3.0.0 + */ +export function map( + F: Functor4 +): (f: (a: A) => B) => (fa: Kind4>) => Kind4> +export function map( + F: Functor3 +): (f: (a: A) => B) => (fa: Kind3>) => Kind3> +export function map( + F: Functor3C +): (f: (a: A) => B) => (fa: Kind3>) => Kind3> +export function map( + F: Functor2 +): (f: (a: A) => B) => (fa: Kind2>) => Kind2> +export function map( + F: Functor2C +): (f: (a: A) => B) => (fa: Kind2>) => Kind2> +export function map( + F: Functor1 +): (f: (a: A) => B) => (fa: Kind>) => Kind> +export function map(F: Functor): (f: (a: A) => B) => (fa: HKT>) => HKT> +export function map(F: Functor): (f: (a: A) => B) => (fa: HKT>) => HKT> { + return map_(F, W.Functor) +} + +/** + * @category type class operations + * @since 3.0.0 + */ +export function of( + F: Pointed4, + M: Monoid +): (a: A) => Kind4> +export function of(F: Pointed3, M: Monoid): (a: A) => Kind3> +export function of( + F: Pointed3C, + M: Monoid +): (a: A) => Kind3> +export function of(F: Pointed2, M: Monoid): (a: A) => Kind2> +export function of(F: Pointed2C, M: Monoid): (a: A) => Kind2> +export function of(F: Pointed1, M: Monoid): (a: A) => Kind> +export function of(F: Pointed, M: Monoid): (a: A) => HKT> +export function of(F: Pointed, M: Monoid): (a: A) => HKT> { + return (a) => F.of([a, M.empty]) +} + +/** + * @category type class operations + * @since 3.0.0 + */ +export function ap( + F: Apply4, + S: Semigroup +): ( + fa: Kind4> +) => (fab: Kind4 B>>) => Kind4> +export function ap( + F: Apply3, + S: Semigroup +): ( + fa: Kind3> +) => (fab: Kind3 B>>) => Kind3> +export function ap( + F: Apply3C, + S: Semigroup +): ( + fa: Kind3> +) => (fab: Kind3 B>>) => Kind3> +export function ap( + F: Apply2, + S: Semigroup +): (fa: Kind2>) => (fab: Kind2 B>>) => Kind2> +export function ap( + F: Apply2C, + S: Semigroup +): (fa: Kind2>) => (fab: Kind2 B>>) => Kind2> +export function ap( + F: Apply1, + S: Semigroup +): (fa: Kind>) => (fab: Kind B>>) => Kind> +export function ap( + F: Apply, + S: Semigroup +): (fa: HKT>) => (fab: HKT B>>) => HKT> +export function ap( + F: Apply, + S: Semigroup +): (fa: HKT>) => (fab: HKT B>>) => HKT> { + return ap_(F, W.getApply(S)) +} + +/** + * @category type class operations + * @since 3.0.0 + */ +export function chain( + M: Chain4, + S: Semigroup +): ( + f: (a: A) => Kind4> +) => (ma: Kind4>) => Kind4> +export function chain( + M: Chain3, + S: Semigroup +): ( + f: (a: A) => Kind3> +) => (ma: Kind3>) => Kind3> +export function chain( + M: Chain3C, + S: Semigroup +): ( + f: (a: A) => Kind3> +) => (ma: Kind3>) => Kind3> +export function chain( + M: Chain2, + S: Semigroup +): (f: (a: A) => Kind2>) => (ma: Kind2>) => Kind2> +export function chain( + M: Chain2C, + S: Semigroup +): (f: (a: A) => Kind2>) => (ma: Kind2>) => Kind2> +export function chain( + M: Chain1, + S: Semigroup +): (f: (a: A) => Kind>) => (ma: Kind>) => Kind> +export function chain( + M: Chain, + S: Semigroup +): (f: (a: A) => HKT>) => (ma: HKT>) => HKT> +export function chain( + M: Chain, + S: Semigroup +): (f: (a: A) => HKT>) => (ma: HKT>) => HKT> { + return (f) => + M.chain(([a, w1]) => + pipe( + f(a), + M.map(([b, w2]) => [b, S.concat(w2)(w1)]) + ) + ) +} + +/** + * @category type class operations + * @since 3.0.0 + */ +export function bimap( + F: Functor4 +): ( + mapSnd: (w: W) => G, + mapFst: (a: A) => B +) => (fwa: Kind4>) => Kind4> +export function bimap( + F: Functor3 +): ( + mapSnd: (w: W) => G, + mapFst: (a: A) => B +) => (fwa: Kind3>) => Kind3> +export function bimap( + F: Functor3C +): ( + mapSnd: (w: W) => G, + mapFst: (a: A) => B +) => (fwa: Kind3>) => Kind3> +export function bimap( + F: Functor2 +): ( + mapSnd: (w: W) => G, + mapFst: (a: A) => B +) => (fwa: Kind2>) => Kind2> +export function bimap( + F: Functor2C +): ( + mapSnd: (w: W) => G, + mapFst: (a: A) => B +) => (fwa: Kind2>) => Kind2> +export function bimap( + F: Functor1 +): (mapSnd: (w: W) => G, mapFst: (a: A) => B) => (fwa: Kind>) => Kind> +export function bimap( + F: Functor +): (mapSnd: (w: W) => G, mapFst: (a: A) => B) => (fwa: HKT>) => HKT> +export function bimap( + F: Functor +): (mapSnd: (w: W) => G, mapFst: (a: A) => B) => (fwa: HKT>) => HKT> { + return (f, g) => F.map(W.bimap(f, g)) +} + +/** + * @category type class operations + * @since 3.0.0 + */ +export function mapLeft( + F: Functor4 +): (mapSnd: (w: W) => G) => (fwa: Kind4>) => Kind4> +export function mapLeft( + F: Functor3 +): (mapSnd: (w: W) => G) => (fwa: Kind3>) => Kind3> +export function mapLeft( + F: Functor3C +): (mapSnd: (w: W) => G) => (fwa: Kind3>) => Kind3> +export function mapLeft( + F: Functor2 +): (mapSnd: (w: W) => G) => (fwa: Kind2>) => Kind2> +export function mapLeft( + F: Functor2C +): (mapSnd: (w: W) => G) => (fwa: Kind2>) => Kind2> +export function mapLeft( + F: Functor1 +): (mapSnd: (w: W) => G) => (fwa: Kind>) => Kind> +export function mapLeft( + F: Functor +): (mapSnd: (w: W) => G) => (fwa: HKT>) => HKT> +export function mapLeft( + F: Functor +): (mapSnd: (w: W) => G) => (fwa: HKT>) => HKT> { + return (f) => F.map(W.mapLeft(f)) +} + +// TODO: alt, zero, fromEither, fromReader, fromState, reduce, foldMap, reduceRight, traverse, contramap + +// ------------------------------------------------------------------------------------- +// utils +// ------------------------------------------------------------------------------------- + +/** + * @since 3.0.0 + */ +export function fst( + F: Functor4 +): (fwa: Kind4>) => Kind4 +export function fst( + F: Functor3 +): (fwa: Kind3>) => Kind3 +export function fst( + F: Functor3C +): (fwa: Kind3>) => Kind3 +export function fst(F: Functor2): (fwa: Kind2>) => Kind2 +export function fst(F: Functor2C): (fwa: Kind2>) => Kind2 +export function fst(F: Functor1): (fwa: Kind>) => Kind +export function fst(F: Functor): (fwa: HKT>) => HKT +export function fst(F: Functor): (fwa: HKT>) => HKT { + return F.map(W.fst) +} + +/** + * @since 3.0.0 + */ +export function snd( + F: Functor4 +): (fwa: Kind4>) => Kind4 +export function snd( + F: Functor3 +): (fwa: Kind3>) => Kind3 +export function snd( + F: Functor3C +): (fwa: Kind3>) => Kind3 +export function snd(F: Functor2): (fwa: Kind2>) => Kind2 +export function snd(F: Functor2C): (fwa: Kind2>) => Kind2 +export function snd(F: Functor1): (fwa: Kind>) => Kind +export function snd(F: Functor): (fwa: HKT>) => HKT +export function snd(F: Functor): (fwa: HKT>) => HKT { + return F.map(W.snd) +} + +// ------------------------------------------------------------------------------------- +// combinators +// ------------------------------------------------------------------------------------- + +/** + * @category combinators + * @since 3.0.0 + */ +export function swap( + F: Functor4 +): (fwa: Kind4>) => Kind4> +export function swap( + F: Functor3 +): (fwa: Kind3>) => Kind3> +export function swap( + F: Functor3C +): (fwa: Kind3>) => Kind3> +export function swap( + F: Functor2 +): (fwa: Kind2>) => Kind2> +export function swap( + F: Functor2C +): (fwa: Kind2>) => Kind2> +export function swap(F: Functor1): (fwa: Kind>) => Kind> +export function swap(F: Functor): (fwa: HKT>) => HKT> +export function swap(F: Functor): (fwa: HKT>) => HKT> { + return F.map(W.swap) +} + +/** + * Modifies the result to include the changes to the accumulator + * + * @category combinators + * @since 3.0.0 + */ +export function listen( + F: Functor4 +): (fwa: Kind4>) => Kind4> +export function listen( + F: Functor3 +): (fwa: Kind3>) => Kind3> +export function listen( + F: Functor3C +): (fwa: Kind3>) => Kind3> +export function listen( + F: Functor2 +): (fwa: Kind2>) => Kind2> +export function listen( + F: Functor2C +): (fwa: Kind2>) => Kind2> +export function listen( + F: Functor1 +): (fwa: Kind>) => Kind> +export function listen(F: Functor): (fwa: HKT>) => HKT> +export function listen(F: Functor): (fwa: HKT>) => HKT> { + return F.map(W.listen) +} + +/** + * Applies the returned function to the accumulator + * + * @category combinators + * @since 3.0.0 + */ +export function pass( + F: Functor4 +): (fwa: Kind4 W]>>) => Kind4> +export function pass( + F: Functor3 +): (fwa: Kind3 W]>>) => Kind3> +export function pass( + F: Functor3C +): (fwa: Kind3 W]>>) => Kind3> +export function pass( + F: Functor2 +): (fwa: Kind2 W]>>) => Kind2> +export function pass( + F: Functor2C +): (fwa: Kind2 W]>>) => Kind2> +export function pass( + F: Functor1 +): (fwa: Kind W]>>) => Kind> +export function pass( + F: Functor +): (fwa: HKT W]>>) => HKT> +export function pass( + F: Functor +): (fwa: HKT W]>>) => HKT> { + return F.map(W.pass) +} + +/** + * Projects a value from modifications made to the accumulator during an action + * + * @category combinators + * @since 3.0.0 + */ +export function listens( + F: Functor4 +): ( + f: (w: W) => B +) => (fwa: Kind4>) => Kind4> +export function listens( + F: Functor3 +): (f: (w: W) => B) => (fwa: Kind3>) => Kind3> +export function listens( + F: Functor3C +): (f: (w: W) => B) => (fwa: Kind3>) => Kind3> +export function listens( + F: Functor2 +): (f: (w: W) => B) => (fwa: Kind2>) => Kind2> +export function listens( + F: Functor2C +): (f: (w: W) => B) => (fwa: Kind2>) => Kind2> +export function listens( + F: Functor1 +): (f: (w: W) => B) => (fwa: Kind>) => Kind> +export function listens( + F: Functor +): (f: (w: W) => B) => (fwa: HKT>) => HKT> +export function listens( + F: Functor +): (f: (w: W) => B) => (fwa: HKT>) => HKT> { + return (f) => F.map(W.listens(f)) +} + +/** + * Modify the final accumulator value by applying a function + * + * @category combinators + * @since 3.0.0 + */ +export function censor( + F: Functor4 +): (f: (w: W) => W) => (fwa: Kind4>) => Kind4> +export function censor( + F: Functor3 +): (f: (w: W) => W) => (fwa: Kind3>) => Kind3> +export function censor( + F: Functor3C +): (f: (w: W) => W) => (fwa: Kind3>) => Kind3> +export function censor( + F: Functor2 +): (f: (w: W) => W) => (fwa: Kind2>) => Kind2> +export function censor( + F: Functor2C +): (f: (w: W) => W) => (fwa: Kind2>) => Kind2> +export function censor( + F: Functor1 +): (f: (w: W) => W) => (fwa: Kind>) => Kind> +export function censor(F: Functor): (f: (w: W) => W) => (fwa: HKT>) => HKT> +export function censor( + F: Functor +): (f: (w: W) => W) => (fwa: HKT>) => HKT> { + return (f) => F.map(W.censor(f)) +} diff --git a/src/index.ts b/src/index.ts index 57c5bb795..3d30740e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,6 +41,7 @@ import * as fromReader from './FromReader' import * as fromState from './FromState' import * as fromTask from './FromTask' import * as fromThese from './FromThese' +import * as fromWriter from './FromWriter' import * as function_ from './function' import * as functor from './Functor' import * as functorWithIndex from './FunctorWithIndex' @@ -76,6 +77,7 @@ import * as readerIO from './ReaderIO' import * as readerT from './ReaderT' import * as readerTask from './ReaderTask' import * as readerTaskEither from './ReaderTaskEither' +import * as readerTaskWriter from './ReaderTaskWriter' import * as readonlyArray from './ReadonlyArray' import * as readonlyMap from './ReadonlyMap' import * as readonlyNonEmptyArray from './ReadonlyNonEmptyArray' @@ -106,11 +108,11 @@ import * as traversable from './Traversable' import * as traversableWithIndex from './TraversableWithIndex' import * as tree from './Tree' import * as tuple from './tuple' -import * as tuple2 from './Tuple2' import * as unfoldable from './Unfoldable' import * as void_ from './void' import * as witherable from './Witherable' import * as writer from './Writer' +import * as writerT from './WriterT' import * as zero from './Zero' export { /** @@ -265,6 +267,10 @@ export { * @since 3.0.0 */ fromThese, + /** + * @since 3.0.0 + */ + fromWriter, /** * @since 3.0.0 */ @@ -401,6 +407,10 @@ export { * @since 3.0.0 */ readerTaskEither, + /** + * @since 3.0.0 + */ + readerTaskWriter, /** * @since 3.0.0 */ @@ -529,10 +539,6 @@ export { * @since 3.0.0 */ tuple, - /** - * @since 3.0.0 - */ - tuple2, /** * @since 3.0.0 */ @@ -549,6 +555,10 @@ export { * @since 3.0.0 */ writer, + /** + * @since 3.0.0 + */ + writerT, /** * @since 3.0.0 */ diff --git a/test/ReaderTaskWriter.ts b/test/ReaderTaskWriter.ts new file mode 100644 index 000000000..5e062c839 --- /dev/null +++ b/test/ReaderTaskWriter.ts @@ -0,0 +1,191 @@ +import { pipe } from '../src/function' +import * as IO from '../src/IO' +import * as R from '../src/Reader' +import * as W from '../src/Writer' +import * as RT from '../src/ReaderTask' +import * as _ from '../src/ReaderTaskWriter' +import * as string from '../src/string' +import * as T from '../src/Task' +import { tuple } from '../src/tuple' +import * as U from './util' + +const make = (a: A, w: W): _.ReaderTaskWriter => RT.of([a, w]) + +describe('ReaderTaskWriter', () => { + // ------------------------------------------------------------------------------------- + // constructors + // ------------------------------------------------------------------------------------- + + it('fromReader', async () => { + U.deepStrictEqual(await pipe(R.of(1), _.fromReader('a'))(undefined)(), [1, 'a']) + }) + + it('fromReaderTask', async () => { + U.deepStrictEqual(await pipe(RT.of(1), _.fromReaderTask('a'))(undefined)(), [1, 'a']) + }) + + it('fromTaskWriter', async () => { + U.deepStrictEqual(await pipe(T.of(W.tell('a')), _.fromTaskWriter)(undefined)(), [undefined, 'a']) + }) + + it('fromIO', async () => { + U.deepStrictEqual(await pipe(IO.of(1), _.fromIO('a'))(undefined)(), [1, 'a']) + }) + + it('fromTask', async () => { + U.deepStrictEqual(await pipe(T.of(1), _.fromTask('a'))(undefined)(), [1, 'a']) + }) + + it('tell', async () => { + U.deepStrictEqual(await _.tell(1)(undefined)(), [undefined, 1]) + }) + + // ------------------------------------------------------------------------------------- + // natural transformations + // ------------------------------------------------------------------------------------- + + it('fromWriter', async () => { + U.deepStrictEqual(await _.fromWriter([1, 'a'])(undefined)(), [1, 'a']) + }) + + it('fromReaderWriter', async () => { + U.deepStrictEqual(await _.fromReaderWriter(R.of([1, 'a']))(undefined)(), [1, 'a']) + }) + + // ------------------------------------------------------------------------------------- + // combinators + // ------------------------------------------------------------------------------------- + + it('swap', async () => { + U.deepStrictEqual(await pipe(make(1, 'a'), _.swap)(undefined)(), ['a', 1]) + }) + + it('listen', async () => { + U.deepStrictEqual(await _.listen(make(1, 'a'))(undefined)(), [[1, 'a'], 'a']) + }) + + it('pass', async () => { + U.deepStrictEqual( + await _.pass( + make( + tuple(1, (w: string) => w + 'b'), + 'a' + ) + )(undefined)(), + [1, 'ab'] + ) + }) + + it('listens', async () => { + const fa: _.ReaderTaskWriter = make(1, 'a') + U.deepStrictEqual( + await pipe( + fa, + _.listens((w) => w.length) + )(undefined)(), + [[1, 1], 'a'] + ) + }) + + it('censor', async () => { + const fa: _.ReaderTaskWriter, number> = make(1, ['a', 'b']) + U.deepStrictEqual( + await pipe( + fa, + _.censor((w) => w.filter((a) => a !== 'a')) + )(undefined)(), + [1, ['b']] + ) + }) + + it('fromWriterK', async () => { + const sum = (a: number, b: number) => [a + b, 'sum'] as const + U.deepStrictEqual(await _.fromWriterK(sum)(1, 2)(undefined)(), [3, 'sum']) + }) + + it('fromTaskWriterK', async () => { + const sum = (a: number, b: number) => T.of([a + b, 'sum'] as const) + U.deepStrictEqual(await _.fromTaskWriterK(sum)(1, 2)(undefined)(), [3, 'sum']) + }) + + it('fromReaderWriterK', async () => { + const sum = (a: number, b: number) => R.of([a + b, 'sum'] as const) + U.deepStrictEqual(await _.fromReaderWriterK(sum)(1, 2)(undefined)(), [3, 'sum']) + }) + + // ------------------------------------------------------------------------------------- + // type class members + // ------------------------------------------------------------------------------------- + + it('map', async () => { + U.deepStrictEqual(await pipe(make(1, 'a'), _.map(U.double))(undefined)(), [2, 'a']) + }) + + it('mapLeft', async () => { + U.deepStrictEqual(await pipe(make('a', 1), _.mapLeft(U.double))(undefined)(), ['a', 2]) + }) + + it('bimap', async () => { + U.deepStrictEqual(await pipe(make(1, 2), _.bimap(U.double, U.double))(undefined)(), [2, 4]) + }) + + // ------------------------------------------------------------------------------------- + // instances + // ------------------------------------------------------------------------------------- + + it('getPointed', async () => { + const P = _.getPointed(string.Monoid) + U.deepStrictEqual(await P.of(1)(undefined)(), [1, '']) + }) + + it('getApply', async () => { + const A = _.getApply(RT.ApplyPar, string.Semigroup) + const f = (s: string) => (n: number): boolean => s.length > n + U.deepStrictEqual(await pipe(make('aa', 'a'), A.map(f), A.ap(make(1, 'b')))(undefined)(), [true, 'ab']) + }) + + it('getApplicative', async () => { + const A = _.getApplicative(RT.ApplyPar, string.Monoid) + const f = (s: string) => (n: number): boolean => s.length > n + U.deepStrictEqual(await pipe(A.of('aa'), A.map(f), A.ap(A.of(1)))(undefined)(), [true, '']) + }) + + it('getChain', async () => { + const C = _.getChain(string.Semigroup) + const double = (n: number): _.ReaderTaskWriter => make(n * 2, 'double') + U.deepStrictEqual(await pipe(make(1, 'start'), C.chain(double))(undefined)(), [2, 'startdouble']) + }) + + it('getMonad', async () => { + const M = _.getMonad(string.Monoid) + const double = (n: number): _.ReaderTaskWriter => M.of(n * 2) + U.deepStrictEqual(await pipe(make(1, 'start'), M.chain(double))(undefined)(), [2, 'start']) + }) + + it('getFromIO', async () => { + const F = _.getFromIO(string.Monoid) + U.deepStrictEqual(await pipe(() => 1, F.fromIO)(undefined)(), [1, '']) + }) + + it('getFromTask', async () => { + const F = _.getFromTask(string.Monoid) + U.deepStrictEqual(await pipe(() => Promise.resolve(1), F.fromTask)(undefined)(), [1, '']) + }) + + it('getFromReader', async () => { + const F = _.getFromReader(string.Monoid) + U.deepStrictEqual(await pipe((env: { readonly a: string }) => env.a, F.fromReader)({ a: 'a' })(), ['a', '']) + }) + + // ------------------------------------------------------------------------------------- + // utils + // ------------------------------------------------------------------------------------- + + it('evaluate', async () => { + U.deepStrictEqual(await pipe(make(1, 'a'), _.evaluate)(undefined)(), 1) + }) + + it('execute', async () => { + U.deepStrictEqual(await pipe(make(1, 'a'), _.execute)(undefined)(), 'a') + }) +}) diff --git a/test/Tuple2.ts b/test/Tuple2.ts deleted file mode 100644 index ffe01e2f3..000000000 --- a/test/Tuple2.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { identity, pipe } from '../src/function' -import * as S from '../src/string' -import * as O from '../src/Option' -import * as _ from '../src/Tuple2' -import * as U from './util' -import * as RA from '../src/ReadonlyArray' -import * as E from '../src/Either' - -describe('Tuple2', () => { - describe('combinators', () => { - it('swap', () => { - U.deepStrictEqual(_.swap([1, 'a']), ['a', 1]) - }) - }) - - describe('type class members', () => { - it('compose', () => { - U.deepStrictEqual(pipe(_.tuple2(1, 'a'), _.compose([true, 2])), [true, 'a']) - }) - - it('mapFst', () => { - U.deepStrictEqual(pipe(_.tuple2(1, 'a'), _.mapFst(U.double)), [2, 'a']) - }) - - it('extract', () => { - U.deepStrictEqual(pipe(_.tuple2(1, 'a'), _.extract), 1) - }) - - it('extend', () => { - const f = (fa: readonly [number, string]): number => _.snd(fa).length + _.fst(fa) - U.deepStrictEqual(pipe([1, 'bb'], _.extend(f)), [3, 'bb']) - }) - - it('bimap', () => { - const f = _.bimap(S.size, U.double) - U.deepStrictEqual(pipe([1, 'a'], f), [2, 1]) - }) - - it('mapSnd', () => { - const f = _.mapSnd(S.size) - U.deepStrictEqual(pipe(_.tuple2(1, 'a'), f), [1, 1]) - }) - - it('duplicate', () => { - U.deepStrictEqual(pipe(_.tuple2(1, 'a'), _.duplicate), [[1, 'a'], 'a']) - }) - - it('reduce', () => { - U.deepStrictEqual( - pipe( - _.tuple2('b', 1), - _.reduce('a', (acc, a) => acc + a) - ), - 'ab' - ) - }) - - it('foldMap', () => { - U.deepStrictEqual(pipe(_.tuple2('a', 1), _.foldMap(S.Monoid)(identity)), 'a') - }) - - it('reduceRight', () => { - U.deepStrictEqual( - pipe( - _.tuple2('b', 1), - _.reduceRight('a', (acc, a) => acc + a) - ), - 'ba' - ) - }) - - it('traverse', () => { - const traverse = _.traverse(O.Applicative)((n: number) => (n > 1 ? O.some(n) : O.none)) - U.deepStrictEqual(traverse([2, 'a']), O.some(_.tuple2(2, 'a'))) - U.deepStrictEqual(traverse([1, 'a']), O.none) - }) - }) - - describe('instances', () => { - it('getApplicative', () => { - const A = _.getApplicative(S.Monoid) - U.deepStrictEqual(A.of(1), [1, '']) - U.deepStrictEqual(pipe(_.tuple2(U.double, 'a'), A.ap([1, 'b'])), [2, 'ab']) - }) - - it('getMonad', () => { - const M = _.getMonad(S.Monoid) - U.deepStrictEqual( - pipe( - _.tuple2(1, 'a'), - M.chain((a) => [a * 2, 'b']) - ), - [2, 'ab'] - ) - }) - }) - - it('getChainRec', () => { - const { chainRec } = _.getChainRec(RA.getMonoid()) - function seqReq(upper: number): readonly [number, ReadonlyArray] { - return pipe( - 1, - chainRec((init) => [init >= upper ? E.right(init) : E.left(init + 1), [init]]) - ) - } - const xs = _.snd(seqReq(10000)) - U.deepStrictEqual(xs.length, 10000) - U.deepStrictEqual(xs[0], 1) - U.deepStrictEqual(xs[xs.length - 1], 10000) - }) -}) diff --git a/test/Writer.ts b/test/Writer.ts index 612e7122a..755dd840a 100644 --- a/test/Writer.ts +++ b/test/Writer.ts @@ -1,4 +1,7 @@ -import { pipe } from '../src/function' +import * as E from '../src/Either' +import { identity, pipe } from '../src/function' +import * as O from '../src/Option' +import * as RA from '../src/ReadonlyArray' import * as S from '../src/string' import { tuple } from '../src/tuple' import * as _ from '../src/Writer' @@ -6,56 +9,118 @@ import * as U from './util' describe('Writer', () => { // ------------------------------------------------------------------------------------- - // type class members + // constructors // ------------------------------------------------------------------------------------- - it('map', () => { - const x: _.Writer = () => [1, 'a'] - U.deepStrictEqual(pipe(x, _.map(U.double))(), [2, 'a']) + it('fromIdentity', () => { + U.deepStrictEqual(pipe(1, _.fromIdentity('a')), [1, 'a']) }) - // ------------------------------------------------------------------------------------- - // constructors - // ------------------------------------------------------------------------------------- - it('tell', () => { - U.deepStrictEqual(_.tell(1)(), [undefined, 1]) + U.deepStrictEqual(_.tell(1), [undefined, 1]) }) // ------------------------------------------------------------------------------------- // combinators // ------------------------------------------------------------------------------------- + it('swap', () => { + U.deepStrictEqual(_.swap([1, 'a']), ['a', 1]) + }) + it('listen', () => { - U.deepStrictEqual(_.listen(() => [1, 'a'])(), [[1, 'a'], 'a']) + U.deepStrictEqual(_.listen([1, 'a']), [[1, 'a'], 'a']) }) it('pass', () => { - U.deepStrictEqual(_.pass(() => [tuple(1, (w: string) => w + 'b'), 'a'])(), [1, 'ab']) + U.deepStrictEqual(_.pass([tuple(1, (w: string) => w + 'b'), 'a']), [1, 'ab']) }) it('listens', () => { - const fa: _.Writer = () => [1, 'a'] + const fa: _.Writer = [1, 'a'] U.deepStrictEqual( pipe( fa, _.listens((w) => w.length) - )(), + ), [[1, 1], 'a'] ) }) it('censor', () => { - const fa: _.Writer, number> = () => [1, ['a', 'b']] + const fa: _.Writer, number> = [1, ['a', 'b']] U.deepStrictEqual( pipe( fa, _.censor((w) => w.filter((a) => a !== 'a')) - )(), + ), [1, ['b']] ) }) + // ------------------------------------------------------------------------------------- + // type class operations + // ------------------------------------------------------------------------------------- + + it('map', () => { + U.deepStrictEqual(pipe([1, 'a'] as const, _.map(U.double)), [2, 'a']) + }) + + it('mapLeft', () => { + U.deepStrictEqual(pipe(['a', 1] as const, _.mapLeft(U.double)), ['a', 2]) + }) + + it('bimap', () => { + U.deepStrictEqual(pipe([1, 'a'], _.bimap(S.size, U.double)), [2, 1]) + }) + + it('compose', () => { + U.deepStrictEqual(pipe([1, 'a'] as const, _.compose([true, 2])), [true, 'a']) + }) + + it('extract', () => { + U.deepStrictEqual(pipe([1, 'a'] as const, _.extract), 1) + }) + + it('extend', () => { + const f = (fa: _.Writer): number => _.snd(fa).length + _.fst(fa) + U.deepStrictEqual(pipe([1, 'bb'], _.extend(f)), [3, 'bb']) + }) + + it('duplicate', () => { + U.deepStrictEqual(pipe([1, 'a'] as const, _.duplicate), [[1, 'a'], 'a']) + }) + + it('reduce', () => { + U.deepStrictEqual( + pipe( + ['b', 1] as const, + _.reduce('a', (acc, a) => acc + a) + ), + 'ab' + ) + }) + + it('foldMap', () => { + U.deepStrictEqual(pipe(['a', 1] as const, _.foldMap(S.Monoid)(identity)), 'a') + }) + + it('reduceRight', () => { + U.deepStrictEqual( + pipe( + ['b', 1] as const, + _.reduceRight('a', (acc, a) => acc + a) + ), + 'ba' + ) + }) + + it('traverse', () => { + const traverse = _.traverse(O.Applicative)((n: number) => (n > 1 ? O.some(n) : O.none)) + U.deepStrictEqual(traverse([2, 'a']), O.some([2, 'a'] as const)) + U.deepStrictEqual(traverse([1, 'a']), O.none) + }) + // ------------------------------------------------------------------------------------- // instances // ------------------------------------------------------------------------------------- @@ -63,21 +128,35 @@ describe('Writer', () => { it('getApplicative', () => { const M = _.getApplicative(S.Monoid) - U.deepStrictEqual(M.of(1)(), [1, '']) + U.deepStrictEqual(M.of(1), [1, '']) - const fab: _.Writer number> = () => [(n: number) => n * 2, 'a'] - const fa: _.Writer = () => [1, 'b'] - U.deepStrictEqual(pipe(fab, M.ap(fa))(), [2, 'ab']) + const fab: _.Writer number> = [(n: number) => n * 2, 'a'] + const fa: _.Writer = [1, 'b'] + U.deepStrictEqual(pipe(fab, M.ap(fa)), [2, 'ab']) }) it('getMonad', () => { const M = _.getMonad(S.Monoid) - U.deepStrictEqual(M.of(1)(), [1, '']) + U.deepStrictEqual(M.of(1), [1, '']) + + const fa: _.Writer = [1, 'a'] + const f = (n: number): _.Writer => [n * 2, 'b'] + U.deepStrictEqual(pipe(fa, M.chain(f)), [2, 'ab']) + }) - const fa: _.Writer = () => [1, 'a'] - const f = (n: number): _.Writer => () => [n * 2, 'b'] - U.deepStrictEqual(pipe(fa, M.chain(f))(), [2, 'ab']) + it('getChainRec', () => { + const { chainRec } = _.getChainRec(RA.getMonoid()) + function seqReq(upper: number): readonly [number, ReadonlyArray] { + return pipe( + 1, + chainRec((init) => [init >= upper ? E.right(init) : E.left(init + 1), [init]]) + ) + } + const xs = _.snd(seqReq(10000)) + U.deepStrictEqual(xs.length, 10000) + U.deepStrictEqual(xs[0], 1) + U.deepStrictEqual(xs[xs.length - 1], 10000) }) // ------------------------------------------------------------------------------------- @@ -85,10 +164,10 @@ describe('Writer', () => { // ------------------------------------------------------------------------------------- it('evaluate', () => { - U.deepStrictEqual(pipe((() => [1, 'a']) as _.Writer, _.evaluate), 1) + U.deepStrictEqual(pipe([1, 'a'] as const, _.evaluate), 1) }) it('execute', () => { - U.deepStrictEqual(pipe((() => [1, 'a']) as _.Writer, _.execute), 'a') + U.deepStrictEqual(pipe([1, 'a'] as const, _.execute), 'a') }) })