diff --git a/docs/modules/Either.ts.md b/docs/modules/Either.ts.md index d99f93b1f..a7616cdba 100644 --- a/docs/modules/Either.ts.md +++ b/docs/modules/Either.ts.md @@ -147,6 +147,8 @@ Added in v2.0.0 - [liftNullable](#liftnullable) - [liftOption](#liftoption) - [mapping](#mapping) + - [as](#as) + - [asUnit](#asunit) - [bimap](#bimap) - [flap](#flap) - [map](#map) @@ -1306,6 +1308,33 @@ Added in v2.15.0 # mapping +## as + +Maps the `Right` value of this `Either` to the specified constant value. + +**Signature** + +```ts +export declare const as: { + (self: Either, a: A): Either + (a: A): (self: Either) => Either +} +``` + +Added in v2.16.0 + +## asUnit + +Maps the `Right` value of this `Either` to the void constant value. + +**Signature** + +```ts +export declare const asUnit: (self: Either) => Either +``` + +Added in v2.16.0 + ## bimap Map a pair of functions over the two type arguments of the bifunctor. diff --git a/docs/modules/IO.ts.md b/docs/modules/IO.ts.md index 8272a6180..c614a6dc4 100644 --- a/docs/modules/IO.ts.md +++ b/docs/modules/IO.ts.md @@ -48,6 +48,8 @@ Added in v2.0.0 - [chain](#chain) - [chainFirst](#chainfirst) - [mapping](#mapping) + - [as](#as) + - [asUnit](#asunit) - [flap](#flap) - [map](#map) - [model](#model) @@ -288,6 +290,30 @@ Added in v2.0.0 # mapping +## as + +Maps the value to the specified constant value. + +**Signature** + +```ts +export declare const as: { (self: IO<_>, a: A): IO; (a: A): <_>(self: IO<_>) => IO } +``` + +Added in v2.16.0 + +## asUnit + +Maps the value to the void constant value. + +**Signature** + +```ts +export declare const asUnit: <_>(self: IO<_>) => IO +``` + +Added in v2.16.0 + ## flap **Signature** diff --git a/docs/modules/IOEither.ts.md b/docs/modules/IOEither.ts.md index b53c64edc..698ae0bf1 100644 --- a/docs/modules/IOEither.ts.md +++ b/docs/modules/IOEither.ts.md @@ -98,6 +98,8 @@ Added in v2.0.0 - [liftNullable](#liftnullable) - [liftOption](#liftoption) - [mapping](#mapping) + - [as](#as) + - [asUnit](#asunit) - [bimap](#bimap) - [flap](#flap) - [map](#map) @@ -1069,6 +1071,33 @@ Added in v2.15.0 # mapping +## as + +Maps the `Right` value of this `IOEither` to the specified constant value. + +**Signature** + +```ts +export declare const as: { + (self: IOEither, a: A): IOEither + (a: A): (self: IOEither) => IOEither +} +``` + +Added in v2.16.0 + +## asUnit + +Maps the `Right` value of this `IOEither` to the void constant value. + +**Signature** + +```ts +export declare const asUnit: (self: IOEither) => IOEither +``` + +Added in v2.16.0 + ## bimap Map a pair of functions over the two type arguments of the bifunctor. diff --git a/docs/modules/IOOption.ts.md b/docs/modules/IOOption.ts.md index 0f126c56d..3cb3e0348 100644 --- a/docs/modules/IOOption.ts.md +++ b/docs/modules/IOOption.ts.md @@ -79,6 +79,8 @@ Added in v2.12.0 - [fromOptionK](#fromoptionk) - [fromPredicate](#frompredicate) - [mapping](#mapping) + - [as](#as) + - [asUnit](#asunit) - [flap](#flap) - [map](#map) - [model](#model) @@ -760,6 +762,33 @@ Added in v2.12.0 # mapping +## as + +Maps the `Some` value of this `IOOption` to the specified constant value. + +**Signature** + +```ts +export declare const as: { + (self: IOOption<_>, a: A): IOOption + (a: A): <_>(self: IOOption<_>) => IOOption +} +``` + +Added in v2.16.0 + +## asUnit + +Maps the `Some` value of this `IOOption` to the void constant value. + +**Signature** + +```ts +export declare const asUnit: <_>(self: IOOption<_>) => IOOption +``` + +Added in v2.16.0 + ## flap **Signature** diff --git a/docs/modules/Option.ts.md b/docs/modules/Option.ts.md index c1923181f..16a180353 100644 --- a/docs/modules/Option.ts.md +++ b/docs/modules/Option.ts.md @@ -144,6 +144,8 @@ Added in v2.0.0 - [fromNullableK](#fromnullablek) - [fromPredicate](#frompredicate) - [mapping](#mapping) + - [as](#as) + - [asUnit](#asunit) - [flap](#flap) - [map](#map) - [model](#model) @@ -1151,6 +1153,30 @@ Added in v2.0.0 # mapping +## as + +Maps the `Some` value of this `Option` to the specified constant value. + +**Signature** + +```ts +export declare const as: { (self: Option<_>, a: A): Option; (a: A): <_>(self: Option<_>) => Option } +``` + +Added in v2.16.0 + +## asUnit + +Maps the `Some` value of this `Option` to the void constant value. + +**Signature** + +```ts +export declare const asUnit: <_>(self: Option<_>) => Option +``` + +Added in v2.16.0 + ## flap **Signature** diff --git a/docs/modules/ReaderEither.ts.md b/docs/modules/ReaderEither.ts.md index 6ba5de902..1696338c2 100644 --- a/docs/modules/ReaderEither.ts.md +++ b/docs/modules/ReaderEither.ts.md @@ -88,6 +88,8 @@ Added in v2.0.0 - [liftNullable](#liftnullable) - [liftOption](#liftoption) - [mapping](#mapping) + - [as](#as) + - [asUnit](#asunit) - [bimap](#bimap) - [flap](#flap) - [map](#map) @@ -1040,6 +1042,33 @@ Added in v2.15.0 # mapping +## as + +Maps the `Right` value of this `ReaderEither` to the specified constant value. + +**Signature** + +```ts +export declare const as: { + (self: ReaderEither, a: A): ReaderEither + (a: A): (self: ReaderEither) => ReaderEither +} +``` + +Added in v2.16.0 + +## asUnit + +Maps the `Right` value of this `ReaderEither` to the void constant value. + +**Signature** + +```ts +export declare const asUnit: (self: ReaderEither) => ReaderEither +``` + +Added in v2.16.0 + ## bimap Map a pair of functions over the two last type arguments of the bifunctor. diff --git a/docs/modules/ReaderIO.ts.md b/docs/modules/ReaderIO.ts.md index 8fecc8a19..ea7b3e568 100644 --- a/docs/modules/ReaderIO.ts.md +++ b/docs/modules/ReaderIO.ts.md @@ -51,6 +51,8 @@ Added in v2.13.0 - [fromIOK](#fromiok) - [fromReaderK](#fromreaderk) - [mapping](#mapping) + - [as](#as) + - [asUnit](#asunit) - [flap](#flap) - [map](#map) - [model](#model) @@ -487,6 +489,33 @@ Added in v2.13.0 # mapping +## as + +Maps the value to the specified constant value. + +**Signature** + +```ts +export declare const as: { + (self: ReaderIO, a: A): ReaderIO + (a: A): (self: ReaderIO) => ReaderIO +} +``` + +Added in v2.16.0 + +## asUnit + +Maps the value to the void constant value. + +**Signature** + +```ts +export declare const asUnit: (self: ReaderIO) => ReaderIO +``` + +Added in v2.16.0 + ## flap **Signature** diff --git a/docs/modules/ReaderTask.ts.md b/docs/modules/ReaderTask.ts.md index c7c5b0019..45c1ee483 100644 --- a/docs/modules/ReaderTask.ts.md +++ b/docs/modules/ReaderTask.ts.md @@ -60,6 +60,8 @@ Added in v2.3.0 - [fromReaderK](#fromreaderk) - [fromTaskK](#fromtaskk) - [mapping](#mapping) + - [as](#as) + - [asUnit](#asunit) - [flap](#flap) - [map](#map) - [model](#model) @@ -620,6 +622,33 @@ Added in v2.4.0 # mapping +## as + +Maps the value to the specified constant value. + +**Signature** + +```ts +export declare const as: { + (self: ReaderTask, a: A): ReaderTask + (a: A): (self: ReaderTask) => ReaderTask +} +``` + +Added in v2.16.0 + +## asUnit + +Maps the value to the void constant value. + +**Signature** + +```ts +export declare const asUnit: (self: ReaderTask) => ReaderTask +``` + +Added in v2.16.0 + ## flap **Signature** diff --git a/docs/modules/ReaderTaskEither.ts.md b/docs/modules/ReaderTaskEither.ts.md index ef3f23056..405d5356c 100644 --- a/docs/modules/ReaderTaskEither.ts.md +++ b/docs/modules/ReaderTaskEither.ts.md @@ -120,6 +120,8 @@ Added in v2.0.0 - [liftNullable](#liftnullable) - [liftOption](#liftoption) - [mapping](#mapping) + - [as](#as) + - [asUnit](#asunit) - [bimap](#bimap) - [flap](#flap) - [map](#map) @@ -1503,6 +1505,33 @@ Added in v2.15.0 # mapping +## as + +Maps the `Right` value of this `ReaderTaskEither` to the specified constant value. + +**Signature** + +```ts +export declare const as: { + (self: ReaderTaskEither, a: A): ReaderTaskEither + (a: A): (self: ReaderTaskEither) => ReaderTaskEither +} +``` + +Added in v2.16.0 + +## asUnit + +Maps the `Right` value of this `ReaderTaskEither` to the void constant value. + +**Signature** + +```ts +export declare const asUnit: (self: ReaderTaskEither) => ReaderTaskEither +``` + +Added in v2.16.0 + ## bimap Map a pair of functions over the two last type arguments of the bifunctor. diff --git a/docs/modules/StateReaderTaskEither.ts.md b/docs/modules/StateReaderTaskEither.ts.md index 5d70df27c..e71907fa0 100644 --- a/docs/modules/StateReaderTaskEither.ts.md +++ b/docs/modules/StateReaderTaskEither.ts.md @@ -93,6 +93,8 @@ Added in v2.0.0 - [fromTaskEitherK](#fromtaskeitherk) - [fromTaskK](#fromtaskk) - [mapping](#mapping) + - [as](#as) + - [asUnit](#asunit) - [bimap](#bimap) - [flap](#flap) - [map](#map) @@ -1046,6 +1048,35 @@ Added in v2.10.0 # mapping +## as + +Maps the `Right` value of this `StateReaderTaskEither` to the specified constant value. + +**Signature** + +```ts +export declare const as: { + (self: StateReaderTaskEither, a: A): StateReaderTaskEither + (a: A): (self: StateReaderTaskEither) => StateReaderTaskEither +} +``` + +Added in v2.16.0 + +## asUnit + +Maps the `Right` value of this `StateReaderTaskEither` to the void constant value. + +**Signature** + +```ts +export declare const asUnit: ( + self: StateReaderTaskEither +) => StateReaderTaskEither +``` + +Added in v2.16.0 + ## bimap Map a pair of functions over the two last type arguments of the bifunctor. diff --git a/docs/modules/Task.ts.md b/docs/modules/Task.ts.md index c627739d1..b8ccb6ab0 100644 --- a/docs/modules/Task.ts.md +++ b/docs/modules/Task.ts.md @@ -55,6 +55,8 @@ Added in v2.0.0 - [lifting](#lifting) - [fromIOK](#fromiok) - [mapping](#mapping) + - [as](#as) + - [asUnit](#asunit) - [flap](#flap) - [map](#map) - [model](#model) @@ -443,6 +445,30 @@ Added in v2.4.0 # mapping +## as + +Maps the value to the specified constant value. + +**Signature** + +```ts +export declare const as: { (self: Task<_>, a: A): Task; (a: A): <_>(self: Task<_>) => Task } +``` + +Added in v2.16.0 + +## asUnit + +Maps the value to the void constant value. + +**Signature** + +```ts +export declare const asUnit: <_>(self: Task<_>) => Task +``` + +Added in v2.16.0 + ## flap **Signature** diff --git a/docs/modules/TaskEither.ts.md b/docs/modules/TaskEither.ts.md index f0a891404..567771356 100644 --- a/docs/modules/TaskEither.ts.md +++ b/docs/modules/TaskEither.ts.md @@ -115,6 +115,8 @@ Added in v2.0.0 - [liftNullable](#liftnullable) - [liftOption](#liftoption) - [mapping](#mapping) + - [as](#as) + - [asUnit](#asunit) - [bimap](#bimap) - [flap](#flap) - [map](#map) @@ -1447,6 +1449,33 @@ Added in v2.15.0 # mapping +## as + +Maps the `Right` value of this `TaskEither` to the specified constant value. + +**Signature** + +```ts +export declare const as: { + (self: TaskEither, a: A): TaskEither + (a: A): (self: TaskEither) => TaskEither +} +``` + +Added in v2.16.0 + +## asUnit + +Maps the `Right` value of this `TaskEither` to the void constant value. + +**Signature** + +```ts +export declare const asUnit: (self: TaskEither) => TaskEither +``` + +Added in v2.16.0 + ## bimap Map a pair of functions over the two type arguments of the bifunctor. diff --git a/docs/modules/TaskOption.ts.md b/docs/modules/TaskOption.ts.md index 398ad189b..ace1f2757 100644 --- a/docs/modules/TaskOption.ts.md +++ b/docs/modules/TaskOption.ts.md @@ -81,6 +81,8 @@ Added in v2.10.0 - [fromPredicate](#frompredicate) - [fromTaskK](#fromtaskk) - [mapping](#mapping) + - [as](#as) + - [asUnit](#asunit) - [flap](#flap) - [map](#map) - [model](#model) @@ -854,6 +856,33 @@ Added in v2.10.0 # mapping +## as + +Maps the `Some` value of this `TaskOption` to the specified constant value. + +**Signature** + +```ts +export declare const as: { + (self: TaskOption<_>, a: A): TaskOption + (a: A): <_>(self: TaskOption<_>) => TaskOption +} +``` + +Added in v2.16.0 + +## asUnit + +Maps the `Some` value of this `TaskOption` to the void constant value. + +**Signature** + +```ts +export declare const asUnit: <_>(self: TaskOption<_>) => TaskOption +``` + +Added in v2.16.0 + ## flap **Signature** diff --git a/src/Either.ts b/src/Either.ts index a45eacf18..7df38a784 100644 --- a/src/Either.ts +++ b/src/Either.ts @@ -87,7 +87,7 @@ import { fromPredicate as fromPredicate_ } from './FromEither' import { dual, flow, identity, LazyArg, pipe } from './function' -import { bindTo as bindTo_, flap as flap_, Functor2, let as let__ } from './Functor' +import { as as as_, asUnit as asUnit_, bindTo as bindTo_, flap as flap_, Functor2, let as let__ } from './Functor' import { HKT } from './HKT' import * as _ from './internal' import { Monad2, Monad2C } from './Monad' @@ -479,6 +479,25 @@ export const Functor: Functor2 = { map: _map } +/** + * Maps the `Right` value of this `Either` to the specified constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const as: { + (self: Either, a: A): Either + (a: A): (self: Either) => Either +} = dual(2, as_(Functor)) + +/** + * Maps the `Right` value of this `Either` to the void constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const asUnit: (self: Either) => Either = asUnit_(Functor) + /** * @category constructors * @since 2.7.0 diff --git a/src/Functor.ts b/src/Functor.ts index ae875f1ff..341fbcd41 100644 --- a/src/Functor.ts +++ b/src/Functor.ts @@ -427,3 +427,38 @@ export function getFunctorComposition(F: Functor, G: Functor): Funct map: (fga, f) => pipe(fga, _map(f)) } } + +/** @internal */ +export function as( + F: Functor4 +): (self: Kind4, a: A) => Kind4 +/** @internal */ +export function as(F: Functor3): (self: Kind3, a: _) => Kind3 +/** @internal */ +export function as(F: Functor2): (self: Kind2, a: A) => Kind2 +/** @internal */ +export function as(F: Functor1): (self: Kind, a: A) => Kind +/** @internal */ +export function as(F: Functor): (self: HKT, a: A) => HKT +/** @internal */ +export function as(F: Functor): (self: HKT, b: A) => HKT { + return (self, b) => F.map(self, () => b) +} + +/** @internal */ +export function asUnit( + F: Functor4 +): (self: Kind4) => Kind4 +/** @internal */ +export function asUnit(F: Functor3): (self: Kind3) => Kind3 +/** @internal */ +export function asUnit(F: Functor2): (self: Kind2) => Kind2 +/** @internal */ +export function asUnit(F: Functor1): <_>(self: Kind) => Kind +/** @internal */ +export function asUnit(F: Functor): <_>(self: HKT) => HKT +/** @internal */ +export function asUnit(F: Functor): <_>(self: HKT) => HKT { + const asM = as(F) + return (self) => asM(self, undefined) +} diff --git a/src/IO.ts b/src/IO.ts index 8a61d21a0..3da88f23c 100644 --- a/src/IO.ts +++ b/src/IO.ts @@ -19,7 +19,7 @@ import * as chainable from './Chain' import { ChainRec1 } from './ChainRec' import { FromIO1 } from './FromIO' import { constant, dual, identity } from './function' -import { bindTo as bindTo_, flap as flap_, Functor1, let as let__ } from './Functor' +import { as as as_, asUnit as asUnit_, bindTo as bindTo_, flap as flap_, Functor1, let as let__ } from './Functor' import * as _ from './internal' import { Monad1 } from './Monad' import { MonadIO1 } from './MonadIO' @@ -118,6 +118,25 @@ export const Functor: Functor1 = { map: _map } +/** + * Maps the value to the specified constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const as: { + (self: IO<_>, a: A): IO + (a: A): <_>(self: IO<_>) => IO +} = dual(2, as_(Functor)) + +/** + * Maps the value to the void constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const asUnit: <_>(self: IO<_>) => IO = asUnit_(Functor) + /** * @category mapping * @since 2.10.0 diff --git a/src/IOEither.ts b/src/IOEither.ts index 9b0c24b57..6b4b65f35 100644 --- a/src/IOEither.ts +++ b/src/IOEither.ts @@ -41,7 +41,7 @@ import { } from './FromEither' import { chainIOK as chainIOK_, FromIO2, fromIOK as fromIOK_, tapIO as tapIO_ } from './FromIO' import { dual, flow, identity, LazyArg, pipe, SK } from './function' -import { bindTo as bindTo_, flap as flap_, Functor2, let as let__ } from './Functor' +import { as as as_, asUnit as asUnit_, bindTo as bindTo_, flap as flap_, Functor2, let as let__ } from './Functor' import * as _ from './internal' import * as I from './IO' import { Monad2, Monad2C } from './Monad' @@ -493,6 +493,25 @@ export const Functor: Functor2 = { map: _map } +/** + * Maps the `Right` value of this `IOEither` to the specified constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const as: { + (self: IOEither, a: A): IOEither + (a: A): (self: IOEither) => IOEither +} = dual(2, as_(Functor)) + +/** + * Maps the `Right` value of this `IOEither` to the void constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const asUnit: (self: IOEither) => IOEither = asUnit_(Functor) + /** * @category mapping * @since 2.10.0 diff --git a/src/IOOption.ts b/src/IOOption.ts index 5cad031df..2f6aa65af 100644 --- a/src/IOOption.ts +++ b/src/IOOption.ts @@ -28,7 +28,7 @@ import { } from './FromEither' import { chainIOK as chainIOK_, FromIO1, fromIOK as fromIOK_, tapIO as tapIO_ } from './FromIO' import { dual, flow, identity, LazyArg, pipe, SK } from './function' -import { bindTo as bindTo_, flap as flap_, Functor1, let as let__ } from './Functor' +import { as as as_, asUnit as asUnit_, bindTo as bindTo_, flap as flap_, Functor1, let as let__ } from './Functor' import * as _ from './internal' import * as I from './IO' import { IOEither } from './IOEither' @@ -377,6 +377,25 @@ export const Functor: Functor1 = { map: _map } +/** + * Maps the `Some` value of this `IOOption` to the specified constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const as: { + (self: IOOption<_>, a: A): IOOption + (a: A): <_>(self: IOOption<_>) => IOOption +} = dual(2, as_(Functor)) + +/** + * Maps the `Some` value of this `IOOption` to the void constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const asUnit: <_>(self: IOOption<_>) => IOOption = asUnit_(Functor) + /** * @category mapping * @since 2.12.0 diff --git a/src/Option.ts b/src/Option.ts index 2d074d841..88115b46e 100644 --- a/src/Option.ts +++ b/src/Option.ts @@ -84,7 +84,7 @@ import { tapEither as tapEither_ } from './FromEither' import { constNull, constUndefined, dual, flow, identity, LazyArg, pipe } from './function' -import { bindTo as bindTo_, flap as flap_, Functor1, let as let__ } from './Functor' +import { as as as_, asUnit as asUnit_, bindTo as bindTo_, flap as flap_, Functor1, let as let__ } from './Functor' import { HKT } from './HKT' import * as _ from './internal' import { Monad1 } from './Monad' @@ -345,6 +345,25 @@ export const Functor: Functor1 = { map: _map } +/** + * Maps the `Some` value of this `Option` to the specified constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const as: { + (self: Option<_>, a: A): Option + (a: A): <_>(self: Option<_>) => Option +} = dual(2, as_(Functor)) + +/** + * Maps the `Some` value of this `Option` to the void constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const asUnit: <_>(self: Option<_>) => Option = asUnit_(Functor) + /** * @category constructors * @since 2.7.0 diff --git a/src/ReaderEither.ts b/src/ReaderEither.ts index 427c6fb45..7b9ac5e93 100644 --- a/src/ReaderEither.ts +++ b/src/ReaderEither.ts @@ -42,7 +42,7 @@ import { fromReaderK as fromReaderK_ } from './FromReader' import { dual, flow, identity, LazyArg, pipe, SK } from './function' -import { bindTo as bindTo_, flap as flap_, Functor3, let as let__ } from './Functor' +import { as as as_, asUnit as asUnit_, bindTo as bindTo_, flap as flap_, Functor3, let as let__ } from './Functor' import * as _ from './internal' import { Monad3, Monad3C } from './Monad' import { MonadThrow3, MonadThrow3C } from './MonadThrow' @@ -515,6 +515,25 @@ export const Functor: Functor3 = { map: _map } +/** + * Maps the `Right` value of this `ReaderEither` to the specified constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const as: { + (self: ReaderEither, a: A): ReaderEither + (a: A): (self: ReaderEither) => ReaderEither +} = dual(2, as_(Functor)) + +/** + * Maps the `Right` value of this `ReaderEither` to the void constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const asUnit: (self: ReaderEither) => ReaderEither = asUnit_(Functor) + /** * @category mapping * @since 2.10.0 diff --git a/src/ReaderIO.ts b/src/ReaderIO.ts index 1e6b28744..096fde2ef 100644 --- a/src/ReaderIO.ts +++ b/src/ReaderIO.ts @@ -14,7 +14,7 @@ import { fromReaderK as fromReaderK_ } from './FromReader' import { dual, flow, identity, pipe, SK } from './function' -import { bindTo as bindTo_, flap as flap_, Functor2 } from './Functor' +import { as as as_, asUnit as asUnit_, bindTo as bindTo_, flap as flap_, Functor2 } from './Functor' import * as _ from './internal' import * as I from './IO' import { IO } from './IO' @@ -168,6 +168,25 @@ export const Functor: Functor2 = { map: _map } +/** + * Maps the value to the specified constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const as: { + (self: ReaderIO, a: A): ReaderIO + (a: A): (self: ReaderIO) => ReaderIO +} = dual(2, as_(Functor)) + +/** + * Maps the value to the void constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const asUnit: (self: ReaderIO) => ReaderIO = asUnit_(Functor) + /** * @category mapping * @since 2.13.0 diff --git a/src/ReaderTask.ts b/src/ReaderTask.ts index 9b25a03b4..f615643cc 100644 --- a/src/ReaderTask.ts +++ b/src/ReaderTask.ts @@ -26,7 +26,7 @@ import { fromTaskK as fromTaskK_ } from './FromTask' import { dual, flow, identity, pipe, SK } from './function' -import { bindTo as bindTo_, flap as flap_, Functor2, let as let__ } from './Functor' +import { as as as_, asUnit as asUnit_, bindTo as bindTo_, flap as flap_, Functor2, let as let__ } from './Functor' import * as _ from './internal' import { IO } from './IO' import { Monad2 } from './Monad' @@ -205,6 +205,25 @@ export const Functor: Functor2 = { map: _map } +/** + * Maps the value to the specified constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const as: { + (self: ReaderTask, a: A): ReaderTask + (a: A): (self: ReaderTask) => ReaderTask +} = dual(2, as_(Functor)) + +/** + * Maps the value to the void constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const asUnit: (self: ReaderTask) => ReaderTask = asUnit_(Functor) + /** * @category mapping * @since 2.10.0 diff --git a/src/ReaderTaskEither.ts b/src/ReaderTaskEither.ts index 5a6d2806e..9f89bf7db 100644 --- a/src/ReaderTaskEither.ts +++ b/src/ReaderTaskEither.ts @@ -50,7 +50,7 @@ import { fromTaskK as fromTaskK_ } from './FromTask' import { dual, flow, identity, LazyArg, pipe, SK } from './function' -import { bindTo as bindTo_, flap as flap_, Functor3, let as let__ } from './Functor' +import { as as as_, asUnit as asUnit_, bindTo as bindTo_, flap as flap_, Functor3, let as let__ } from './Functor' import * as _ from './internal' import { IO } from './IO' import { IOEither } from './IOEither' @@ -803,6 +803,25 @@ export const Functor: Functor3 = { map: _map } +/** + * Maps the `Right` value of this `ReaderTaskEither` to the specified constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const as: { + (self: ReaderTaskEither, a: A): ReaderTaskEither + (a: A): (self: ReaderTaskEither) => ReaderTaskEither +} = dual(2, as_(Functor)) + +/** + * Maps the `Right` value of this `ReaderTaskEither` to the void constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const asUnit: (self: ReaderTaskEither) => ReaderTaskEither = asUnit_(Functor) + /** * @category mapping * @since 2.10.0 diff --git a/src/StateReaderTaskEither.ts b/src/StateReaderTaskEither.ts index d794488bb..ad0951cd1 100644 --- a/src/StateReaderTaskEither.ts +++ b/src/StateReaderTaskEither.ts @@ -44,7 +44,7 @@ import { fromTaskK as fromTaskK_ } from './FromTask' import { dual, flow, identity, LazyArg, pipe } from './function' -import { bindTo as bindTo_, flap as flap_, Functor4, let as let__ } from './Functor' +import { as as as_, asUnit as asUnit_, bindTo as bindTo_, flap as flap_, Functor4, let as let__ } from './Functor' import * as _ from './internal' import { IO } from './IO' import { IOEither } from './IOEither' @@ -537,6 +537,26 @@ export const Functor: Functor4 = { map: _map } +/** + * Maps the `Right` value of this `StateReaderTaskEither` to the specified constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const as: { + (self: StateReaderTaskEither, a: A): StateReaderTaskEither + (a: A): (self: StateReaderTaskEither) => StateReaderTaskEither +} = dual(2, as_(Functor)) + +/** + * Maps the `Right` value of this `StateReaderTaskEither` to the void constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const asUnit: (self: StateReaderTaskEither) => StateReaderTaskEither = + asUnit_(Functor) + /** * @category mapping * @since 2.10.0 diff --git a/src/Task.ts b/src/Task.ts index 4b57d7021..d02ecbf7b 100644 --- a/src/Task.ts +++ b/src/Task.ts @@ -22,7 +22,7 @@ import * as chainable from './Chain' import { chainIOK as chainIOK_, FromIO1, fromIOK as fromIOK_, tapIO as tapIO_ } from './FromIO' import { FromTask1 } from './FromTask' import { dual, identity, pipe } from './function' -import { bindTo as bindTo_, flap as flap_, Functor1, let as let__ } from './Functor' +import { as as as_, asUnit as asUnit_, bindTo as bindTo_, flap as flap_, Functor1, let as let__ } from './Functor' import * as _ from './internal' import { IO } from './IO' import { Monad1 } from './Monad' @@ -197,6 +197,25 @@ export const Functor: Functor1 = { map: _map } +/** + * Maps the value to the specified constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const as: { + (self: Task<_>, a: A): Task + (a: A): <_>(self: Task<_>) => Task +} = dual(2, as_(Functor)) + +/** + * Maps the value to the void constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const asUnit: <_>(self: Task<_>) => Task = asUnit_(Functor) + /** * @category mapping * @since 2.10.0 diff --git a/src/TaskEither.ts b/src/TaskEither.ts index ae4cace47..063268703 100644 --- a/src/TaskEither.ts +++ b/src/TaskEither.ts @@ -49,7 +49,7 @@ import { fromTaskK as fromTaskK_ } from './FromTask' import { dual, flow, identity, LazyArg, pipe, SK } from './function' -import { bindTo as bindTo_, flap as flap_, Functor2, let as let__ } from './Functor' +import { as as as_, asUnit as asUnit_, bindTo as bindTo_, flap as flap_, Functor2, let as let__ } from './Functor' import * as _ from './internal' import { IO } from './IO' import { IOEither } from './IOEither' @@ -748,6 +748,25 @@ export const Functor: Functor2 = { map: _map } +/** + * Maps the `Right` value of this `TaskEither` to the specified constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const as: { + (self: TaskEither, a: A): TaskEither + (a: A): (self: TaskEither) => TaskEither +} = dual(2, as_(Functor)) + +/** + * Maps the `Right` value of this `TaskEither` to the void constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const asUnit: (self: TaskEither) => TaskEither = asUnit_(Functor) + /** * @category mapping * @since 2.10.0 diff --git a/src/TaskOption.ts b/src/TaskOption.ts index 10b9b85a5..33c4054c1 100644 --- a/src/TaskOption.ts +++ b/src/TaskOption.ts @@ -29,7 +29,7 @@ import { fromTaskK as fromTaskK_ } from './FromTask' import { dual, flow, identity, LazyArg, pipe, SK } from './function' -import { bindTo as bindTo_, flap as flap_, Functor1, let as let__ } from './Functor' +import { as as as_, asUnit as asUnit_, bindTo as bindTo_, flap as flap_, Functor1, let as let__ } from './Functor' import * as _ from './internal' import { IO } from './IO' import { Monad1 } from './Monad' @@ -420,6 +420,25 @@ export const Functor: Functor1 = { map: _map } +/** + * Maps the `Some` value of this `TaskOption` to the specified constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const as: { + (self: TaskOption<_>, a: A): TaskOption + (a: A): <_>(self: TaskOption<_>) => TaskOption +} = dual(2, as_(Functor)) + +/** + * Maps the `Some` value of this `TaskOption` to the void constant value. + * + * @category mapping + * @since 2.16.0 + */ +export const asUnit: <_>(self: TaskOption<_>) => TaskOption = asUnit_(Functor) + /** * @category mapping * @since 2.10.0 diff --git a/test/Either.ts b/test/Either.ts index 89a4a3bc7..93b626838 100644 --- a/test/Either.ts +++ b/test/Either.ts @@ -695,4 +695,14 @@ describe.concurrent('Either', () => { U.deepStrictEqual(f('a'), _.right(1)) U.deepStrictEqual(f(''), _.left(new Error('empty string'))) }) + + it('as', () => { + U.deepStrictEqual(pipe(_.right('a'), _.as('b')), _.right('b')) + U.deepStrictEqual(_.as(_.of('a'), 'b'), _.right('b')) + U.deepStrictEqual(_.as(_.left('error'), 'b'), _.left('error')) + }) + + it('asUnit', () => { + U.deepStrictEqual(pipe(_.of('a'), _.asUnit), _.of(undefined)) + }) }) diff --git a/test/IO.ts b/test/IO.ts index b2b563e3b..7f62c07a6 100644 --- a/test/IO.ts +++ b/test/IO.ts @@ -117,4 +117,12 @@ describe.concurrent('IO', () => { U.deepStrictEqual(log, [1, 2]) }) }) + + it('as', () => { + U.deepStrictEqual(pipe(_.of('a'), _.as('b'))(), 'b') + }) + + it('asUnit', () => { + U.deepStrictEqual(pipe(_.of('a'), _.asUnit)(), undefined) + }) }) diff --git a/test/IOEither.ts b/test/IOEither.ts index b84c1ad10..e51f20514 100644 --- a/test/IOEither.ts +++ b/test/IOEither.ts @@ -699,4 +699,14 @@ describe.concurrent('IOEither', () => { U.deepStrictEqual(pipe(_.left('error'), _.tapIO(add))(), E.left('error')) U.deepStrictEqual(ref, [1]) }) + + it('as', () => { + U.deepStrictEqual(pipe(_.right('a'), _.as('b'))(), E.right('b')) + U.deepStrictEqual(_.as(_.of('a'), 'b')(), E.right('b')) + U.deepStrictEqual(_.as(_.left('error'), 'b')(), E.left('error')) + }) + + it('asUnit', () => { + U.deepStrictEqual(pipe(_.of('a'), _.asUnit)(), E.of(undefined)) + }) }) diff --git a/test/IOOption.ts b/test/IOOption.ts index e4962b7b8..f3507fd18 100644 --- a/test/IOOption.ts +++ b/test/IOOption.ts @@ -265,4 +265,14 @@ describe.concurrent('IOOption', () => { U.deepStrictEqual(pipe(_.none, _.tapIO(add))(), O.none) U.deepStrictEqual(ref, [1]) }) + + it('as', () => { + U.deepStrictEqual(pipe(_.some('a'), _.as('b'))(), O.some('b')) + U.deepStrictEqual(_.as(_.of('a'), 'b')(), O.some('b')) + U.deepStrictEqual(_.as(_.none, 'b')(), O.none) + }) + + it('asUnit', () => { + U.deepStrictEqual(pipe(_.some('a'), _.asUnit)(), O.some(undefined)) + }) }) diff --git a/test/Option.ts b/test/Option.ts index 8bdcf3a71..73dc98c0b 100644 --- a/test/Option.ts +++ b/test/Option.ts @@ -558,4 +558,14 @@ describe.concurrent('Option', () => { const g = (s: string) => E.left(s.length) U.deepStrictEqual(pipe(_.some('a'), _.chainFirstEitherK(g)), _.none) }) + + it('as', () => { + U.deepStrictEqual(pipe(_.some('a'), _.as('b')), _.some('b')) + U.deepStrictEqual(_.as(_.of('a'), 'b'), _.some('b')) + U.deepStrictEqual(_.as(_.none, 'b'), _.none) + }) + + it('asUnit', () => { + U.deepStrictEqual(pipe(_.some('a'), _.asUnit), _.some(undefined)) + }) }) diff --git a/test/ReaderEither.ts b/test/ReaderEither.ts index 59a66dcf8..7622031f5 100644 --- a/test/ReaderEither.ts +++ b/test/ReaderEither.ts @@ -413,4 +413,14 @@ describe.concurrent('ReaderEither', () => { const g = (s: string) => E.left(s.length) U.deepStrictEqual(pipe(_.right('a'), _.chainFirstEitherK(g))({}), E.left(1)) }) + + it('as', () => { + U.deepStrictEqual(pipe(_.right('a'), _.as('b'))(undefined), E.right('b')) + U.deepStrictEqual(_.as(_.of('a'), 'b')(undefined), E.right('b')) + U.deepStrictEqual(_.as(_.left('error'), 'b')(undefined), E.left('error')) + }) + + it('asUnit', () => { + U.deepStrictEqual(pipe(_.of('a'), _.asUnit)(undefined), E.of(undefined)) + }) }) diff --git a/test/ReaderIO.ts b/test/ReaderIO.ts index d5aadebdc..b8768df3b 100644 --- a/test/ReaderIO.ts +++ b/test/ReaderIO.ts @@ -167,4 +167,12 @@ describe.concurrent('ReaderIO', () => { U.deepStrictEqual(pipe(_.ask(), _.tapIO(add))(1)(), 1) U.deepStrictEqual(ref, [1]) }) + + it('as', () => { + U.deepStrictEqual(pipe(_.of('a'), _.as('b'))('c')(), 'b') + }) + + it('asUnit', () => { + U.deepStrictEqual(pipe(_.of('a'), _.asUnit)('b')(), undefined) + }) }) diff --git a/test/ReaderTask.ts b/test/ReaderTask.ts index 89a05f62d..071e8a517 100644 --- a/test/ReaderTask.ts +++ b/test/ReaderTask.ts @@ -295,4 +295,12 @@ describe.concurrent('ReaderTask', () => { U.deepStrictEqual(await pipe(_.ask(), _.tapIO(add))(1)(), 1) U.deepStrictEqual(ref, [1]) }) + + it('as', async () => { + U.deepStrictEqual(await pipe(_.of('a'), _.as('b'))('c')(), 'b') + }) + + it('asUnit', async () => { + U.deepStrictEqual(await pipe(_.of('a'), _.asUnit)('b')(), undefined) + }) }) diff --git a/test/ReaderTaskEither.ts b/test/ReaderTaskEither.ts index f56bccb97..8fb92b97f 100644 --- a/test/ReaderTaskEither.ts +++ b/test/ReaderTaskEither.ts @@ -751,4 +751,14 @@ describe.concurrent('ReaderTaskEither', () => { U.deepStrictEqual(await pipe(_.left('error'), _.tapIO(add))(undefined)(), E.left('error')) U.deepStrictEqual(ref, [1]) }) + + it('as', async () => { + U.deepStrictEqual(await pipe(_.right('a'), _.as('b'))(undefined)(), E.right('b')) + U.deepStrictEqual(await _.as(_.of('a'), 'b')(undefined)(), E.right('b')) + U.deepStrictEqual(await _.as(_.left('error'), 'b')(undefined)(), E.left('error')) + }) + + it('asUnit', async () => { + U.deepStrictEqual(await pipe(_.of('a'), _.asUnit)(undefined)(), E.of(undefined)) + }) }) diff --git a/test/StateReaderTaskEither.ts b/test/StateReaderTaskEither.ts index c2a3387b3..4b9d50a0b 100644 --- a/test/StateReaderTaskEither.ts +++ b/test/StateReaderTaskEither.ts @@ -523,4 +523,13 @@ describe.concurrent('StateReaderTaskEither', () => { U.deepStrictEqual(await pipe(_.left('error'), _.tapIO(add), _.evaluate(state))(undefined)(), E.left('error')) U.deepStrictEqual(ref, [1]) }) + + it('as', async () => { + U.deepStrictEqual(await pipe(_.right('a'), _.as('b'), _.evaluate(state))(undefined)(), E.right('b')) + U.deepStrictEqual(await pipe(_.as(_.left('error'), 'b'), _.evaluate(state))(undefined)(), E.left('error')) + }) + + it('asUnit', async () => { + U.deepStrictEqual(await pipe(_.of('a'), _.asUnit, _.evaluate(state))(undefined)(), E.of(undefined)) + }) }) diff --git a/test/Task.ts b/test/Task.ts index e42c7e750..830bb7cfc 100644 --- a/test/Task.ts +++ b/test/Task.ts @@ -279,4 +279,12 @@ describe.concurrent('Task', () => { U.deepStrictEqual(log, [0, 1, 2, 3]) }) }) + + it('as', async () => { + U.deepStrictEqual(await pipe(_.of('a'), _.as('b'))(), 'b') + }) + + it('asUnit', async () => { + U.deepStrictEqual(await pipe(_.of('a'), _.asUnit)(), undefined) + }) }) diff --git a/test/TaskEither.ts b/test/TaskEither.ts index ed063078f..d22086263 100644 --- a/test/TaskEither.ts +++ b/test/TaskEither.ts @@ -862,4 +862,14 @@ describe.concurrent('TaskEither', () => { U.deepStrictEqual(await pipe(_.left('error'), _.tapIO(add))(), E.left('error')) U.deepStrictEqual(ref, [1]) }) + + it('as', async () => { + U.deepStrictEqual(await pipe(_.right('a'), _.as('b'))(), E.right('b')) + U.deepStrictEqual(await _.as(_.of('a'), 'b')(), E.right('b')) + U.deepStrictEqual(await _.as(_.left('error'), 'b')(), E.left('error')) + }) + + it('asUnit', async () => { + U.deepStrictEqual(await pipe(_.of('a'), _.asUnit)(), E.of(undefined)) + }) }) diff --git a/test/TaskOption.ts b/test/TaskOption.ts index f297e858a..17c90ba13 100644 --- a/test/TaskOption.ts +++ b/test/TaskOption.ts @@ -390,4 +390,14 @@ describe.concurrent('TaskOption', () => { U.deepStrictEqual(await pipe(_.none, _.tapIO(add))(), O.none) U.deepStrictEqual(ref, [1]) }) + + it('as', async () => { + U.deepStrictEqual(await pipe(_.some('a'), _.as('b'))(), O.some('b')) + U.deepStrictEqual(await _.as(_.of('a'), 'b')(), O.some('b')) + U.deepStrictEqual(await _.as(_.none, 'b')(), O.none) + }) + + it('asUnit', async () => { + U.deepStrictEqual(await pipe(_.some('a'), _.asUnit)(), O.some(undefined)) + }) })