diff --git a/CHANGELOG.md b/CHANGELOG.md index feea88a2a..e4f5c78a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,8 @@ > - [Experimental] > - [Deprecation] -**Note**: Gaps between patch versions are faulty/broken releases. **Note**: A feature tagged as Experimental is in a +**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.7.1 @@ -23,10 +24,12 @@ high state of flux, you're at risk of it changing without notice. - **Polish** - `Array` - relax `sort` signature (@gcanti) + - relax `sortBy` signature (@gcanti) - `Map` - export `mapWithIndex` (@gcanti) - `ReadonlyArray` - relax `sort` signature (@gcanti) + - relax `sortBy` signature (@gcanti) - `ReadonlyMap` - export `mapWithIndex` (@gcanti) diff --git a/docs/modules/Array.ts.md b/docs/modules/Array.ts.md index ee81bd300..0d4ad42be 100644 --- a/docs/modules/Array.ts.md +++ b/docs/modules/Array.ts.md @@ -863,7 +863,7 @@ etc... **Signature** ```ts -export declare const sortBy: (ords: Ord[]) => (as: A[]) => A[] +export declare const sortBy: (ords: Ord[]) => (as: A[]) => A[] ``` **Example** diff --git a/docs/modules/ReadonlyArray.ts.md b/docs/modules/ReadonlyArray.ts.md index 4e611f87c..0fea5e05f 100644 --- a/docs/modules/ReadonlyArray.ts.md +++ b/docs/modules/ReadonlyArray.ts.md @@ -863,7 +863,7 @@ etc... **Signature** ```ts -export declare function sortBy(ords: ReadonlyArray>): (as: ReadonlyArray) => ReadonlyArray +export declare function sortBy(ords: ReadonlyArray>): (as: ReadonlyArray) => ReadonlyArray ``` **Example** diff --git a/dtslint/ts3.5/Array.ts b/dtslint/ts3.5/Array.ts index 320bf974e..ab2f8d416 100644 --- a/dtslint/ts3.5/Array.ts +++ b/dtslint/ts3.5/Array.ts @@ -1,6 +1,7 @@ import * as _ from '../../src/Array' import { pipe } from '../../src/pipeable' import { eqNumber } from '../../src/Eq' +import { Ord } from '../../src/Ord' declare const us: Array declare const ns: Array @@ -133,3 +134,31 @@ _.zip(['a', 'b']) // $ExpectType (as: A[]) => [A, string][] _.cons(0, [1, 2]) // $ExpectType NonEmptyArray _.cons(0) // $ExpectType (tail: number[]) => NonEmptyArray + +// +// sort +// + +declare const ord1: Ord<{ readonly a: string }> +interface X1 { + readonly a: string + readonly b: number +} +declare const x1s: Array + +_.sort(ord1)(x1s) // $ExpectType X1[] + +// +// sortBy +// + +declare const ord2: Ord +declare const ord3: Ord +interface X2 { + readonly a: string + readonly b: number + readonly c: boolean +} +declare const x2s: Array + +_.sortBy([ord2, ord3])(x2s) // $ExpectType X2[] diff --git a/dtslint/ts3.5/ReadonlyArray.ts b/dtslint/ts3.5/ReadonlyArray.ts index cc6ffc525..d11f4b1ee 100644 --- a/dtslint/ts3.5/ReadonlyArray.ts +++ b/dtslint/ts3.5/ReadonlyArray.ts @@ -1,6 +1,7 @@ import * as _ from '../../src/ReadonlyArray' import { pipe } from '../../src/pipeable' import { eqNumber } from '../../src/Eq' +import { Ord } from '../../src/Ord' declare const rus: ReadonlyArray declare const rns: ReadonlyArray @@ -124,3 +125,31 @@ _.zip(['a', 'b']) // $ExpectType (as: readonly A[]) => readonly (readonly [A, _.cons(0, [1, 2]) // $ExpectType ReadonlyNonEmptyArray _.cons(0) // $ExpectType (tail: readonly number[]) => ReadonlyNonEmptyArray + +// +// sort +// + +declare const ord1: Ord<{ readonly a: string }> +interface X1 { + readonly a: string + readonly b: number +} +declare const x1s: ReadonlyArray + +_.sort(ord1)(x1s) // $ExpectType ReadonlyArray + +// +// sortBy +// + +declare const ord2: Ord +declare const ord3: Ord +interface X2 { + readonly a: string + readonly b: number + readonly c: boolean +} +declare const x2s: ReadonlyArray + +_.sortBy([ord2, ord3])(x2s) // $ExpectType ReadonlyArray diff --git a/src/Array.ts b/src/Array.ts index 362ffbc61..eced21821 100644 --- a/src/Array.ts +++ b/src/Array.ts @@ -801,7 +801,7 @@ export const uniq: (E: Eq) => (as: Array) => Array = RA.uniq as any * @category combinators * @since 2.0.0 */ -export const sortBy: (ords: Array>) => (as: Array) => Array = RA.sortBy as any +export const sortBy: (ords: Array>) => (as: Array) => Array = RA.sortBy as any /** * A useful recursion pattern for processing an array to produce a new array, often used for "chopping" up the input diff --git a/src/ReadonlyArray.ts b/src/ReadonlyArray.ts index a518d6ece..9325e27f0 100644 --- a/src/ReadonlyArray.ts +++ b/src/ReadonlyArray.ts @@ -1170,8 +1170,8 @@ export function uniq(E: Eq): (as: ReadonlyArray) => ReadonlyArray { * @category combinators * @since 2.5.0 */ -export function sortBy(ords: ReadonlyArray>): (as: ReadonlyArray) => ReadonlyArray { - const M = getOrdMonoid() +export function sortBy(ords: ReadonlyArray>): (as: ReadonlyArray) => ReadonlyArray { + const M = getOrdMonoid() return sort(ords.reduce(M.concat, M.empty)) }