Skip to content

Commit

Permalink
fix filter overloads in NonEmptyArray / ReadonlyNonEmptyArray, c…
Browse files Browse the repository at this point in the history
…loses #1388
  • Loading branch information
gcanti committed Feb 2, 2021
1 parent 9759cb0 commit 239cf0e
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,11 @@
**Note**: A feature tagged as Experimental is in a
high state of flux, you're at risk of it changing without notice.

# 2.9.4

- **Bug Fix**
- fix `filter` overloads in `NonEmptyArray` / `ReadonlyNonEmptyArray`, closes #1388 (@gcanti)

# 2.9.3

- **Polish**
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/NonEmptyArray.ts.md
Expand Up @@ -353,7 +353,7 @@ Added in v2.0.0
```ts
export declare function filter<A, B extends A>(
refinement: Refinement<A, B>
): (nea: NonEmptyArray<A>) => Option<NonEmptyArray<A>>
): (nea: NonEmptyArray<A>) => Option<NonEmptyArray<B>>
export declare function filter<A>(predicate: Predicate<A>): (nea: NonEmptyArray<A>) => Option<NonEmptyArray<A>>
```

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ReadonlyNonEmptyArray.ts.md
Expand Up @@ -913,7 +913,7 @@ Added in v2.6.3
```ts
export declare function filter<A, B extends A>(
refinement: Refinement<A, B>
): (nea: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<A>>
): (nea: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<B>>
export declare function filter<A>(
predicate: Predicate<A>
): (nea: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<A>>
Expand Down
18 changes: 17 additions & 1 deletion dtslint/ts3.5/NonEmptyArray.ts
Expand Up @@ -2,7 +2,6 @@ import * as _ from '../../src/NonEmptyArray'
import { Ord } from '../../src/Ord'
import { pipe } from '../../src/function'

declare const as: Array<string>
declare const neas: _.NonEmptyArray<string>
declare const nens: _.NonEmptyArray<number>
declare const netns: _.NonEmptyArray<[number, string]>
Expand Down Expand Up @@ -89,3 +88,20 @@ pipe(
_.bind('a', () => _.of(1)),
_.bind('b', () => _.of('b'))
)

//
// filter
//

declare const isNumber1: (sn: string | number) => sn is number
declare const isNumber2: (sn: unknown) => sn is number
declare const neasn: _.NonEmptyArray<string | number>

// $ExpectType Option<NonEmptyArray<number>>
pipe(neasn, _.filter(isNumber1))
// $ExpectType Option<NonEmptyArray<number>>
_.filter(isNumber1)(neasn)
// $ExpectType Option<NonEmptyArray<number>>
pipe(neasn, _.filter(isNumber2))
// $ExpectType Option<NonEmptyArray<number>>
_.filter(isNumber2)(neasn)
17 changes: 17 additions & 0 deletions dtslint/ts3.5/ReadonlyNonEmptyArray.ts
Expand Up @@ -89,3 +89,20 @@ pipe(
_.bind('a', () => _.of(1)),
_.bind('b', () => _.of('b'))
)

//
// filter
//

declare const isNumber1: (sn: string | number) => sn is number
declare const isNumber2: (sn: unknown) => sn is number
declare const neasn: _.ReadonlyNonEmptyArray<string | number>

// $ExpectType Option<ReadonlyNonEmptyArray<number>>
pipe(neasn, _.filter(isNumber1))
// $ExpectType Option<ReadonlyNonEmptyArray<number>>
_.filter(isNumber1)(neasn)
// $ExpectType Option<ReadonlyNonEmptyArray<number>>
pipe(neasn, _.filter(isNumber2))
// $ExpectType Option<ReadonlyNonEmptyArray<number>>
_.filter(isNumber2)(neasn)
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "fp-ts",
"version": "2.9.3",
"version": "2.9.4",
"description": "Functional programming in TypeScript",
"main": "lib/index.js",
"module": "es6/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/NonEmptyArray.ts
Expand Up @@ -283,7 +283,7 @@ export function copy<A>(nea: NonEmptyArray<A>): NonEmptyArray<A> {
*/
export function filter<A, B extends A>(
refinement: Refinement<A, B>
): (nea: NonEmptyArray<A>) => Option<NonEmptyArray<A>>
): (nea: NonEmptyArray<A>) => Option<NonEmptyArray<B>>
export function filter<A>(predicate: Predicate<A>): (nea: NonEmptyArray<A>) => Option<NonEmptyArray<A>>
export function filter<A>(predicate: Predicate<A>): (nea: NonEmptyArray<A>) => Option<NonEmptyArray<A>> {
return RNEA.filter(predicate) as any
Expand Down
2 changes: 1 addition & 1 deletion src/ReadonlyNonEmptyArray.ts
Expand Up @@ -343,7 +343,7 @@ export function modifyAt<A>(
*/
export function filter<A, B extends A>(
refinement: Refinement<A, B>
): (nea: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<A>>
): (nea: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<B>>
export function filter<A>(predicate: Predicate<A>): (nea: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<A>>
export function filter<A>(
predicate: Predicate<A>
Expand Down

0 comments on commit 239cf0e

Please sign in to comment.