From dbf6cf98bdba23afc9a2573df79c240efaed9dfc Mon Sep 17 00:00:00 2001 From: gcanti Date: Tue, 9 Jun 2020 16:14:04 +0200 Subject: [PATCH] add pipeable top level wither / wilt --- CHANGELOG.md | 6 + docs/modules/Array.ts.md | 25 +++ docs/modules/Option.ts.md | 25 +++ docs/modules/ReadonlyArray.ts.md | 25 +++ docs/modules/ReadonlyRecord.ts.md | 25 +++ docs/modules/Record.ts.md | 25 +++ docs/modules/Witherable.ts.md | 272 ++++++++++++++++++++++++++++++ package.json | 2 +- src/Array.ts | 18 +- src/Option.ts | 24 ++- src/ReadonlyArray.ts | 26 ++- src/ReadonlyRecord.ts | 60 +++++-- src/Record.ts | 14 +- src/Witherable.ts | 220 ++++++++++++++++++++++++ test/Option.ts | 14 +- test/ReadonlyArray.ts | 10 +- test/ReadonlyRecord.ts | 13 +- 17 files changed, 761 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7344174f7..2fc878315 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,12 @@ **Note**: Gaps between patch versions are faulty/broken releases. **Note**: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice. +# 2.6.5 + +- **Polish** + - export a pipeable `wither` function from all modules which admit a `Witherable` instance (@gcanti) + - export a pipeable `wilt` function from all modules which admit a `Witherable` instance (@gcanti) + # 2.6.4 - **Bug Fix** diff --git a/docs/modules/Array.ts.md b/docs/modules/Array.ts.md index 441fd6e6c..2f9a9d7d0 100644 --- a/docs/modules/Array.ts.md +++ b/docs/modules/Array.ts.md @@ -50,6 +50,9 @@ Added in v2.0.0 - [chain](#chain) - [chainFirst](#chainfirst) - [flatten](#flatten) +- [Whitherable](#whitherable) + - [wilt](#wilt) + - [wither](#wither) - [combinators](#combinators) - [chop](#chop) - [copy](#copy) @@ -461,6 +464,28 @@ assert.deepStrictEqual(flatten([[1], [2], [3]]), [1, 2, 3]) Added in v2.0.0 +# Whitherable + +## wilt + +**Signature** + +```ts +export declare const wilt: PipeableWilt1<'Array'> +``` + +Added in v2.6.5 + +## wither + +**Signature** + +```ts +export declare const wither: PipeableWither1<'Array'> +``` + +Added in v2.6.5 + # combinators ## chop diff --git a/docs/modules/Option.ts.md b/docs/modules/Option.ts.md index 39c0e18ac..0d6a4b9f6 100644 --- a/docs/modules/Option.ts.md +++ b/docs/modules/Option.ts.md @@ -53,6 +53,9 @@ Added in v2.0.0 - [Traversable](#traversable) - [sequence](#sequence) - [traverse](#traverse) +- [Whitherable](#whitherable) + - [wilt](#wilt) + - [wither](#wither) - [combinators](#combinators) - [mapNullable](#mapnullable) - [constructors](#constructors) @@ -370,6 +373,28 @@ export declare const traverse: PipeableTraverse1<'Option'> Added in v2.6.3 +# Whitherable + +## wilt + +**Signature** + +```ts +export declare const wilt: PipeableWilt1<'Option'> +``` + +Added in v2.6.5 + +## wither + +**Signature** + +```ts +export declare const wither: PipeableWither1<'Option'> +``` + +Added in v2.6.5 + # combinators ## mapNullable diff --git a/docs/modules/ReadonlyArray.ts.md b/docs/modules/ReadonlyArray.ts.md index 44b71166a..5193a892c 100644 --- a/docs/modules/ReadonlyArray.ts.md +++ b/docs/modules/ReadonlyArray.ts.md @@ -50,6 +50,9 @@ Added in v2.5.0 - [chain](#chain) - [chainFirst](#chainfirst) - [flatten](#flatten) +- [Whitherable](#whitherable) + - [wilt](#wilt) + - [wither](#wither) - [combinators](#combinators) - [chop](#chop) - [difference](#difference) @@ -467,6 +470,28 @@ assert.deepStrictEqual(flatten([[1], [2], [3]]), [1, 2, 3]) Added in v2.5.0 +# Whitherable + +## wilt + +**Signature** + +```ts +export declare const wilt: PipeableWilt1<'ReadonlyArray'> +``` + +Added in v2.6.5 + +## wither + +**Signature** + +```ts +export declare const wither: PipeableWither1<'ReadonlyArray'> +``` + +Added in v2.6.5 + # combinators ## chop diff --git a/docs/modules/ReadonlyRecord.ts.md b/docs/modules/ReadonlyRecord.ts.md index 1f9270a32..633466981 100644 --- a/docs/modules/ReadonlyRecord.ts.md +++ b/docs/modules/ReadonlyRecord.ts.md @@ -24,6 +24,9 @@ Added in v2.5.0 - [foldMap](#foldmap) - [reduce](#reduce) - [reduceRight](#reduceright) +- [Whitherable](#whitherable) + - [wilt](#wilt) + - [wither](#wither) - [combinators](#combinators) - [deleteAt](#deleteat) - [filterMapWithIndex](#filtermapwithindex) @@ -187,6 +190,28 @@ export declare const reduceRight: (b: B, f: (a: A, b: B) => B) => (fa: Rea Added in v2.5.0 +# Whitherable + +## wilt + +**Signature** + +```ts +export declare const wilt: PipeableWilt1<'ReadonlyRecord'> +``` + +Added in v2.6.5 + +## wither + +**Signature** + +```ts +export declare const wither: PipeableWither1<'ReadonlyRecord'> +``` + +Added in v2.6.5 + # combinators ## deleteAt diff --git a/docs/modules/Record.ts.md b/docs/modules/Record.ts.md index dce573470..a6881e048 100644 --- a/docs/modules/Record.ts.md +++ b/docs/modules/Record.ts.md @@ -24,6 +24,9 @@ Added in v2.0.0 - [foldMap](#foldmap) - [reduce](#reduce) - [reduceRight](#reduceright) +- [Whitherable](#whitherable) + - [wilt](#wilt) + - [wither](#wither) - [model](#model) - [URI](#uri) - [URI (type alias)](#uri-type-alias) @@ -176,6 +179,28 @@ export declare const reduceRight: (b: B, f: (a: A, b: B) => B) => (fa: Rec Added in v2.0.0 +# Whitherable + +## wilt + +**Signature** + +```ts +export declare const wilt: PipeableWilt1<'Record'> +``` + +Added in v2.6.5 + +## wither + +**Signature** + +```ts +export declare const wither: PipeableWither1<'Record'> +``` + +Added in v2.6.5 + # model ## URI diff --git a/docs/modules/Witherable.ts.md b/docs/modules/Witherable.ts.md index 008f86dc9..4b51ad609 100644 --- a/docs/modules/Witherable.ts.md +++ b/docs/modules/Witherable.ts.md @@ -35,6 +35,16 @@ Added in v2.0.0 - [Witherable2C (interface)](#witherable2c-interface) - [Witherable3 (interface)](#witherable3-interface) - [utils](#utils) + - [PipeableWilt (interface)](#pipeablewilt-interface) + - [PipeableWilt1 (interface)](#pipeablewilt1-interface) + - [PipeableWilt2 (interface)](#pipeablewilt2-interface) + - [PipeableWilt2C (interface)](#pipeablewilt2c-interface) + - [PipeableWilt3 (interface)](#pipeablewilt3-interface) + - [PipeableWither (interface)](#pipeablewither-interface) + - [PipeableWither1 (interface)](#pipeablewither1-interface) + - [PipeableWither2 (interface)](#pipeablewither2-interface) + - [PipeableWither2C (interface)](#pipeablewither2c-interface) + - [PipeableWither3 (interface)](#pipeablewither3-interface) - [Wilt (interface)](#wilt-interface) - [Wilt1 (interface)](#wilt1-interface) - [Wilt2 (interface)](#wilt2-interface) @@ -124,6 +134,268 @@ Added in v2.0.0 # utils +## PipeableWilt (interface) + +**Signature** + +```ts +export interface PipeableWilt { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (wa: HKT) => Kind3, HKT>> + (F: Applicative3C): ( + f: (a: A) => Kind3> + ) => (wa: HKT) => Kind3, HKT>> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (wa: HKT) => Kind2, HKT>> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (wa: HKT) => Kind2, HKT>> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (wa: HKT) => Kind, HKT>> + (F: Applicative): ( + f: (a: A) => HKT> + ) => (wa: HKT) => HKT, HKT>> +} +``` + +Added in v2.6.5 + +## PipeableWilt1 (interface) + +**Signature** + +```ts +export interface PipeableWilt1 { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (wa: Kind) => Kind3, Kind>> + (F: Applicative3C): ( + f: (a: A) => Kind3> + ) => (wa: Kind) => Kind3, Kind>> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (wa: Kind) => Kind2, Kind>> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (wa: Kind) => Kind2, Kind>> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (wa: Kind) => Kind, Kind>> + (F: Applicative): ( + f: (a: A) => HKT> + ) => (wa: Kind) => HKT, Kind>> +} +``` + +Added in v2.6.5 + +## PipeableWilt2 (interface) + +**Signature** + +```ts +export interface PipeableWilt2 { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (wa: Kind2) => Kind3, Kind2>> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (wa: Kind2) => Kind2, Kind2>> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (wa: Kind2) => Kind2, Kind2>> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (wa: Kind2) => Kind, Kind2>> + (F: Applicative): ( + f: (a: A) => HKT> + ) => (wa: Kind2) => HKT, Kind2>> +} +``` + +Added in v2.6.5 + +## PipeableWilt2C (interface) + +**Signature** + +```ts +export interface PipeableWilt2C { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (wa: Kind2) => Kind3, Kind2>> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (wa: Kind2) => Kind2, Kind2>> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (wa: Kind2) => Kind2, Kind2>> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (wa: Kind2) => Kind, Kind2>> + (F: Applicative): ( + f: (a: A) => HKT> + ) => (wa: Kind2) => HKT, Kind2>> +} +``` + +Added in v2.6.5 + +## PipeableWilt3 (interface) + +**Signature** + +```ts +export interface PipeableWilt3 { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (wa: Kind3) => Kind3, Kind3>> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (wa: Kind3) => Kind2, Kind3>> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (wa: Kind3) => Kind2, Kind3>> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (wa: Kind3) => Kind, Kind3>> + (F: Applicative): ( + f: (a: A) => HKT> + ) => (wa: Kind3) => HKT, Kind3>> +} +``` + +Added in v2.6.5 + +## PipeableWither (interface) + +**Signature** + +```ts +export interface PipeableWither { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (ta: HKT) => Kind3> + (F: Applicative3C): ( + f: (a: A) => Kind3> + ) => (ta: HKT) => Kind3> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (ta: HKT) => Kind2> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (ta: HKT) => Kind2> + (F: Applicative1): (f: (a: A) => Kind>) => (ta: HKT) => Kind> + (F: Applicative): (f: (a: A) => HKT>) => (ta: HKT) => HKT> +} +``` + +Added in v2.6.5 + +## PipeableWither1 (interface) + +**Signature** + +```ts +export interface PipeableWither1 { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (ta: Kind) => Kind3> + (F: Applicative3C): ( + f: (a: A) => Kind3> + ) => (ta: Kind) => Kind3> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (ta: Kind) => Kind2> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (ta: Kind) => Kind2> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (ta: Kind) => Kind> + (F: Applicative): (f: (a: A) => HKT>) => (ta: Kind) => HKT> +} +``` + +Added in v2.6.5 + +## PipeableWither2 (interface) + +**Signature** + +```ts +export interface PipeableWither2 { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (ta: Kind2) => Kind3> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (ta: Kind2) => Kind2> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (ta: Kind2) => Kind2> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (ta: Kind2) => Kind> + (F: Applicative): (f: (a: A) => HKT>) => (ta: Kind2) => HKT> +} +``` + +Added in v2.6.5 + +## PipeableWither2C (interface) + +**Signature** + +```ts +export interface PipeableWither2C { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (ta: Kind2) => Kind3> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (ta: Kind2) => Kind2> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (ta: Kind2) => Kind2> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (ta: Kind2) => Kind> + (F: Applicative): (f: (a: A) => HKT>) => (ta: Kind2) => HKT> +} +``` + +Added in v2.6.5 + +## PipeableWither3 (interface) + +**Signature** + +```ts +export interface PipeableWither3 { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (ta: Kind3) => Kind3> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (ta: Kind3) => Kind2> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (ta: Kind3) => Kind2> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (ta: Kind3) => Kind> + (F: Applicative): ( + f: (a: A) => HKT> + ) => (ta: Kind3) => HKT> +} +``` + +Added in v2.6.5 + ## Wilt (interface) **Signature** diff --git a/package.json b/package.json index b16f3641b..3612ab6b0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fp-ts", - "version": "2.6.4", + "version": "2.6.5", "description": "Functional programming in TypeScript", "files": [ "lib", diff --git a/src/Array.ts b/src/Array.ts index b75143d28..c332d474a 100644 --- a/src/Array.ts +++ b/src/Array.ts @@ -18,10 +18,10 @@ import { Option } from './Option' import { Ord } from './Ord' import * as RA from './ReadonlyArray' import { Show } from './Show' -import { TraversableWithIndex1, PipeableTraverseWithIndex1 } from './TraversableWithIndex' +import { PipeableTraverse1, Traversable1 } from './Traversable' +import { PipeableTraverseWithIndex1, TraversableWithIndex1 } from './TraversableWithIndex' import { Unfoldable1 } from './Unfoldable' -import { Witherable1 } from './Witherable' -import { Traversable1, PipeableTraverse1 } from './Traversable' +import { PipeableWilt1, PipeableWither1, Witherable1 } from './Witherable' // ------------------------------------------------------------------------------------- // model @@ -1190,6 +1190,18 @@ export const sequence: Traversable1['sequence'] = RA.sequence as any */ export const traverseWithIndex: PipeableTraverseWithIndex1 = RA.traverseWithIndex as any +/** + * @category Whitherable + * @since 2.6.5 + */ +export const wither: PipeableWither1 = RA.wither as any + +/** + * @category Whitherable + * @since 2.6.5 + */ +export const wilt: PipeableWilt1 = RA.wilt as any + /** * @category instances * @since 2.0.0 diff --git a/src/Option.ts b/src/Option.ts index 4b71a1091..c03a98e58 100644 --- a/src/Option.ts +++ b/src/Option.ts @@ -29,7 +29,7 @@ import { Ord } from './Ord' import { Semigroup } from './Semigroup' import { Show } from './Show' import { Traversable1, PipeableTraverse1 } from './Traversable' -import { Witherable1 } from './Witherable' +import { Witherable1, PipeableWither1, PipeableWilt1 } from './Witherable' // ------------------------------------------------------------------------------------- // model @@ -652,6 +652,28 @@ export const sequence: Traversable1['sequence'] = (F: Applicative) => return isNone(ta) ? F.of(none) : F.map(ta.value, some) } +/** + * @category Whitherable + * @since 2.6.5 + */ +export const wither: PipeableWither1 = ( + F: Applicative +): ((f: (a: A) => HKT>) => (ta: Option) => HKT>) => { + const witherF = wither_(F) + return (f) => (ta) => witherF(ta, f) +} + +/** + * @category Whitherable + * @since 2.6.5 + */ +export const wilt: PipeableWilt1 = ( + F: Applicative +): ((f: (a: A) => HKT>) => (wa: Option) => HKT, Option>>) => { + const wiltF = wilt_(F) + return (f) => (ta) => wiltF(ta, f) +} + // ------------------------------------------------------------------------------------- // instances // ------------------------------------------------------------------------------------- diff --git a/src/ReadonlyArray.ts b/src/ReadonlyArray.ts index 01ba940f2..46c4eca0c 100644 --- a/src/ReadonlyArray.ts +++ b/src/ReadonlyArray.ts @@ -26,7 +26,7 @@ import { ReadonlyNonEmptyArray } from './ReadonlyNonEmptyArray' import { Show } from './Show' import { TraversableWithIndex1, PipeableTraverseWithIndex1 } from './TraversableWithIndex' import { Unfoldable1 } from './Unfoldable' -import { Witherable1 } from './Witherable' +import { Witherable1, PipeableWither1, PipeableWilt1 } from './Witherable' import { Traversable1, PipeableTraverse1 } from './Traversable' /** @@ -1876,6 +1876,30 @@ export const traverseWithIndex: PipeableTraverseWithIndex1 = ( return (f) => (ta) => traverseWithIndexF(ta, f) } +/** + * @category Whitherable + * @since 2.6.5 + */ +export const wither: PipeableWither1 = ( + F: Applicative +): ((f: (a: A) => HKT>) => (ta: ReadonlyArray) => HKT>) => { + const witherF = wither_(F) + return (f) => (ta) => witherF(ta, f) +} + +/** + * @category Whitherable + * @since 2.6.5 + */ +export const wilt: PipeableWilt1 = ( + F: Applicative +): (( + f: (a: A) => HKT> +) => (wa: ReadonlyArray) => HKT, ReadonlyArray>>) => { + const wiltF = wilt_(F) + return (f) => (ta) => wiltF(ta, f) +} + /** * @category instances * @since 2.5.0 diff --git a/src/ReadonlyRecord.ts b/src/ReadonlyRecord.ts index 583abc0e0..b494c63ae 100644 --- a/src/ReadonlyRecord.ts +++ b/src/ReadonlyRecord.ts @@ -18,7 +18,7 @@ import { Semigroup } from './Semigroup' import { Show } from './Show' import { TraversableWithIndex1 } from './TraversableWithIndex' import { Unfoldable, Unfoldable1 } from './Unfoldable' -import { Witherable1 } from './Witherable' +import { Witherable1, PipeableWither1, PipeableWilt1 } from './Witherable' /** * @category model @@ -510,6 +510,30 @@ export function sequence( return traverseWithIndex(F)((_, a) => a) } +/** + * @category Whitherable + * @since 2.6.5 + */ +export const wither: PipeableWither1 = ( + F: Applicative +): ((f: (a: A) => HKT>) => (ta: ReadonlyRecord) => HKT>) => { + const witherF = wither_(F) + return (f) => (ta) => witherF(ta, f) +} + +/** + * @category Whitherable + * @since 2.6.5 + */ +export const wilt: PipeableWilt1 = ( + F: Applicative +): (( + f: (a: A) => HKT> +) => (wa: ReadonlyRecord) => HKT, ReadonlyRecord>>) => { + const wiltF = wilt_(F) + return (f) => (ta) => wiltF(ta, f) +} + /** * @since 2.5.0 */ @@ -896,6 +920,23 @@ const traverseWithIndex_ = (F: Applicative) => ( return fr } +const wither_ = ( + F: Applicative +): ((wa: ReadonlyRecord, f: (a: A) => HKT>) => HKT>) => { + const traverseF = traverse_(F) + return (wa, f) => F.map(traverseF(wa, f), compact) +} + +const wilt_ = ( + F: Applicative +): (( + wa: ReadonlyRecord, + f: (a: A) => HKT> +) => HKT, ReadonlyRecord>>) => { + const traverseF = traverse_(F) + return (wa, f) => F.map(traverseF(wa, f), separate) +} + /** * @category Filterable * @since 2.5.0 @@ -1039,20 +1080,7 @@ export const readonlyRecord: FunctorWithIndex1 & partitionWithIndex: partitionWithIndex_, filterMapWithIndex: filterMapWithIndex_, filterWithIndex: filterWithIndex_, - wither: ( - F: Applicative - ): ((wa: ReadonlyRecord, f: (a: A) => HKT>) => HKT>) => { - const traverseF = traverse_(F) - return (wa, f) => F.map(traverseF(wa, f), compact) - }, - wilt: ( - F: Applicative - ): (( - wa: ReadonlyRecord, - f: (a: A) => HKT> - ) => HKT, ReadonlyRecord>>) => { - const traverseF = traverse_(F) - return (wa, f) => F.map(traverseF(wa, f), separate) - }, + wither: wither_, + wilt: wilt_, traverseWithIndex: traverseWithIndex_ } diff --git a/src/Record.ts b/src/Record.ts index fee3ca2d6..1620d7539 100644 --- a/src/Record.ts +++ b/src/Record.ts @@ -19,7 +19,7 @@ import { Semigroup } from './Semigroup' import { Show } from './Show' import { TraversableWithIndex1 } from './TraversableWithIndex' import { Unfoldable, Unfoldable1 } from './Unfoldable' -import { Witherable1 } from './Witherable' +import { Witherable1, PipeableWither1, PipeableWilt1 } from './Witherable' /* tslint:disable:readonly-array */ @@ -329,6 +329,18 @@ export function sequence(F: Applicative): (ta: Record return RR.sequence(F) } +/** + * @category Whitherable + * @since 2.6.5 + */ +export const wither: PipeableWither1 = RR.wither as any + +/** + * @category Whitherable + * @since 2.6.5 + */ +export const wilt: PipeableWilt1 = RR.wilt as any + /** * @since 2.0.0 */ diff --git a/src/Witherable.ts b/src/Witherable.ts index 73f49b268..53832dfa2 100644 --- a/src/Witherable.ts +++ b/src/Witherable.ts @@ -334,3 +334,223 @@ export interface Wilt3 { f: (a: A) => HKT> ) => HKT, Kind3>> } + +// +// pipeable `Wither` +// + +/** + * @since 2.6.5 + */ +export interface PipeableWither { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (ta: HKT) => Kind3> + (F: Applicative3C): ( + f: (a: A) => Kind3> + ) => (ta: HKT) => Kind3> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (ta: HKT) => Kind2> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (ta: HKT) => Kind2> + (F: Applicative1): (f: (a: A) => Kind>) => (ta: HKT) => Kind> + (F: Applicative): (f: (a: A) => HKT>) => (ta: HKT) => HKT> +} + +/** + * @since 2.6.5 + */ +export interface PipeableWither1 { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (ta: Kind) => Kind3> + (F: Applicative3C): ( + f: (a: A) => Kind3> + ) => (ta: Kind) => Kind3> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (ta: Kind) => Kind2> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (ta: Kind) => Kind2> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (ta: Kind) => Kind> + (F: Applicative): (f: (a: A) => HKT>) => (ta: Kind) => HKT> +} + +/** + * @since 2.6.5 + */ +export interface PipeableWither2 { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (ta: Kind2) => Kind3> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (ta: Kind2) => Kind2> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (ta: Kind2) => Kind2> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (ta: Kind2) => Kind> + (F: Applicative): (f: (a: A) => HKT>) => (ta: Kind2) => HKT> +} + +/** + * @since 2.6.5 + */ +export interface PipeableWither2C { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (ta: Kind2) => Kind3> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (ta: Kind2) => Kind2> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (ta: Kind2) => Kind2> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (ta: Kind2) => Kind> + (F: Applicative): (f: (a: A) => HKT>) => (ta: Kind2) => HKT> +} + +/** + * @since 2.6.5 + */ +export interface PipeableWither3 { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (ta: Kind3) => Kind3> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (ta: Kind3) => Kind2> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (ta: Kind3) => Kind2> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (ta: Kind3) => Kind> + (F: Applicative): ( + f: (a: A) => HKT> + ) => (ta: Kind3) => HKT> +} + +// +// pipeable `Wilt` +// + +/** + * @since 2.6.5 + */ +export interface PipeableWilt { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (wa: HKT) => Kind3, HKT>> + (F: Applicative3C): ( + f: (a: A) => Kind3> + ) => (wa: HKT) => Kind3, HKT>> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (wa: HKT) => Kind2, HKT>> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (wa: HKT) => Kind2, HKT>> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (wa: HKT) => Kind, HKT>> + (F: Applicative): ( + f: (a: A) => HKT> + ) => (wa: HKT) => HKT, HKT>> +} + +/** + * @since 2.6.5 + */ +export interface PipeableWilt1 { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (wa: Kind) => Kind3, Kind>> + (F: Applicative3C): ( + f: (a: A) => Kind3> + ) => (wa: Kind) => Kind3, Kind>> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (wa: Kind) => Kind2, Kind>> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (wa: Kind) => Kind2, Kind>> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (wa: Kind) => Kind, Kind>> + (F: Applicative): ( + f: (a: A) => HKT> + ) => (wa: Kind) => HKT, Kind>> +} + +/** + * @since 2.6.5 + */ +export interface PipeableWilt2 { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (wa: Kind2) => Kind3, Kind2>> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (wa: Kind2) => Kind2, Kind2>> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (wa: Kind2) => Kind2, Kind2>> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (wa: Kind2) => Kind, Kind2>> + (F: Applicative): ( + f: (a: A) => HKT> + ) => (wa: Kind2) => HKT, Kind2>> +} + +/** + * @since 2.6.5 + */ +export interface PipeableWilt2C { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (wa: Kind2) => Kind3, Kind2>> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (wa: Kind2) => Kind2, Kind2>> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (wa: Kind2) => Kind2, Kind2>> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (wa: Kind2) => Kind, Kind2>> + (F: Applicative): ( + f: (a: A) => HKT> + ) => (wa: Kind2) => HKT, Kind2>> +} + +/** + * @since 2.6.5 + */ +export interface PipeableWilt3 { + (F: Applicative3): ( + f: (a: A) => Kind3> + ) => (wa: Kind3) => Kind3, Kind3>> + (F: Applicative2): ( + f: (a: A) => Kind2> + ) => (wa: Kind3) => Kind2, Kind3>> + (F: Applicative2C): ( + f: (a: A) => Kind2> + ) => (wa: Kind3) => Kind2, Kind3>> + (F: Applicative1): ( + f: (a: A) => Kind> + ) => (wa: Kind3) => Kind, Kind3>> + (F: Applicative): ( + f: (a: A) => HKT> + ) => (wa: Kind3) => HKT, Kind3>> +} diff --git a/test/Option.ts b/test/Option.ts index f0503bc7a..f78ec773f 100644 --- a/test/Option.ts +++ b/test/Option.ts @@ -403,19 +403,17 @@ describe('Option', () => { describe('Witherable', () => { it('wither', () => { - const witherIdentity = _.option.wither(I.identity) const f = (n: number) => I.identity.of(p(n) ? _.some(n + 1) : _.none) - assert.deepStrictEqual(witherIdentity(_.none, f), I.identity.of(_.none)) - assert.deepStrictEqual(witherIdentity(_.some(1), f), I.identity.of(_.none)) - assert.deepStrictEqual(witherIdentity(_.some(3), f), I.identity.of(_.some(4))) + assert.deepStrictEqual(pipe(_.none, _.wither(I.identity)(f)), I.identity.of(_.none)) + assert.deepStrictEqual(pipe(_.some(1), _.wither(I.identity)(f)), I.identity.of(_.none)) + assert.deepStrictEqual(pipe(_.some(3), _.wither(I.identity)(f)), I.identity.of(_.some(4))) }) it('wilt', () => { - const wiltIdentity = _.option.wilt(I.identity) const f = (n: number) => I.identity.of(p(n) ? right(n + 1) : left(n - 1)) - assert.deepStrictEqual(wiltIdentity(_.none, f), I.identity.of({ left: _.none, right: _.none })) - assert.deepStrictEqual(wiltIdentity(_.some(1), f), I.identity.of({ left: _.some(0), right: _.none })) - assert.deepStrictEqual(wiltIdentity(_.some(3), f), I.identity.of({ left: _.none, right: _.some(4) })) + assert.deepStrictEqual(pipe(_.none, _.wilt(I.identity)(f)), I.identity.of({ left: _.none, right: _.none })) + assert.deepStrictEqual(pipe(_.some(1), _.wilt(I.identity)(f)), I.identity.of({ left: _.some(0), right: _.none })) + assert.deepStrictEqual(pipe(_.some(3), _.wilt(I.identity)(f)), I.identity.of({ left: _.none, right: _.some(4) })) }) }) diff --git a/test/ReadonlyArray.ts b/test/ReadonlyArray.ts index a00fa30f2..650a4c39e 100644 --- a/test/ReadonlyArray.ts +++ b/test/ReadonlyArray.ts @@ -33,17 +33,15 @@ describe('ReadonlyArray', () => { }) it('wither', () => { - const witherIdentity = _.readonlyArray.wither(I.identity) const f = (n: number) => I.identity.of(n > 2 ? O.some(n + 1) : O.none) - assert.deepStrictEqual(witherIdentity([], f), I.identity.of([])) - assert.deepStrictEqual(witherIdentity([1, 3], f), I.identity.of([4])) + assert.deepStrictEqual(F.pipe([], _.wither(I.identity)(f)), I.identity.of([])) + assert.deepStrictEqual(F.pipe([1, 3], _.wither(I.identity)(f)), I.identity.of([4])) }) it('wilt', () => { - const wiltIdentity = _.readonlyArray.wilt(I.identity) const f = (n: number) => I.identity.of(n > 2 ? E.right(n + 1) : E.left(n - 1)) - assert.deepStrictEqual(wiltIdentity([], f), I.identity.of({ left: [], right: [] })) - assert.deepStrictEqual(wiltIdentity([1, 3], f), I.identity.of({ left: [0], right: [4] })) + assert.deepStrictEqual(F.pipe([], _.wilt(I.identity)(f)), I.identity.of({ left: [], right: [] })) + assert.deepStrictEqual(F.pipe([1, 3], _.wilt(I.identity)(f)), I.identity.of({ left: [0], right: [4] })) }) }) diff --git a/test/ReadonlyRecord.ts b/test/ReadonlyRecord.ts index 0e09f3749..77b821050 100644 --- a/test/ReadonlyRecord.ts +++ b/test/ReadonlyRecord.ts @@ -327,17 +327,18 @@ describe('ReadonlyRecord', () => { }) it('wither', () => { - const witherIdentity = _.readonlyRecord.wither(I.identity) const f = (n: number) => I.identity.of(p(n) ? some(n + 1) : none) - assert.deepStrictEqual(witherIdentity({}, f), I.identity.of<_.ReadonlyRecord>({})) - assert.deepStrictEqual(witherIdentity({ a: 1, b: 3 }, f), I.identity.of({ b: 4 })) + assert.deepStrictEqual(pipe({}, _.wither(I.identity)(f)), I.identity.of<_.ReadonlyRecord>({})) + assert.deepStrictEqual(pipe({ a: 1, b: 3 }, _.wither(I.identity)(f)), I.identity.of({ b: 4 })) }) it('wilt', () => { - const wiltIdentity = _.readonlyRecord.wilt(I.identity) const f = (n: number) => I.identity.of(p(n) ? right(n + 1) : left(n - 1)) - assert.deepStrictEqual(wiltIdentity({}, f), I.identity.of({ left: {}, right: {} })) - assert.deepStrictEqual(wiltIdentity({ a: 1, b: 3 }, f), I.identity.of({ left: { a: 0 }, right: { b: 4 } })) + assert.deepStrictEqual(pipe({}, _.wilt(I.identity)(f)), I.identity.of({ left: {}, right: {} })) + assert.deepStrictEqual( + pipe({ a: 1, b: 3 }, _.wilt(I.identity)(f)), + I.identity.of({ left: { a: 0 }, right: { b: 4 } }) + ) }) it('every', () => {