Skip to content

Commit

Permalink
deprecate NonEmptyArray.make in favour of cons
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed May 21, 2019
1 parent ed6dd92 commit 93b05b8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
**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.

# 1.18.2

- **Polish**
- fix `NonEmptyArray` definition (@gcanti)
- **Deprecation**
- deprecate `NonEmptyArray.make` in favour of `cons` (@gcanti)

# 1.18.1

- **Bug Fix**
Expand Down
10 changes: 6 additions & 4 deletions docs/modules/NonEmptyArray2v.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Data structure which represents non-empty arrays
- [head (function)](#head-function)
- [insertAt (function)](#insertat-function)
- [last (function)](#last-function)
- [make (function)](#make-function)
- [~~make~~ (function)](#make-function)
- [max (function)](#max-function)
- [min (function)](#min-function)
- [modifyAt (function)](#modifyat-function)
Expand All @@ -54,8 +54,8 @@ Data structure which represents non-empty arrays
```ts
export interface NonEmptyArray<A> extends Array<A> {
0: A
map: <B>(f: (a: A, index: number, nea: NonEmptyArray<A>) => B) => NonEmptyArray<B>
concat: (as: Array<A>) => NonEmptyArray<A>
map<B>(f: (a: A, index: number, nea: NonEmptyArray<A>) => B): NonEmptyArray<B>
concat(as: Array<A>): NonEmptyArray<A>
}
```

Expand Down Expand Up @@ -380,7 +380,9 @@ export function last<A>(nea: NonEmptyArray<A>): A { ... }

Added in v1.15.0

# make (function)
# ~~make~~ (function)

Use `cons` instead

**Signature**

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fp-ts",
"version": "1.18.1",
"version": "1.18.2",
"description": "Functional programming in TypeScript",
"files": [
"lib",
Expand Down
11 changes: 7 additions & 4 deletions src/NonEmptyArray2v.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export type URI = typeof URI
*/
export interface NonEmptyArray<A> extends Array<A> {
0: A
map: <B>(f: (a: A, index: number, nea: NonEmptyArray<A>) => B) => NonEmptyArray<B>
concat: (as: Array<A>) => NonEmptyArray<A>
map<B>(f: (a: A, index: number, nea: NonEmptyArray<A>) => B): NonEmptyArray<B>
concat(as: Array<A>): NonEmptyArray<A>
}

/**
Expand All @@ -46,10 +46,13 @@ export const getShow = <A>(S: Show<A>): Show<NonEmptyArray<A>> => {
}

/**
* Use `cons` instead
*
* @since 1.15.0
* @deprecated
*/
export function make<A>(head: A, tail: Array<A>): NonEmptyArray<A> {
return [head, ...tail] as any
return A.cons(head, tail)
}

/**
Expand Down Expand Up @@ -207,7 +210,7 @@ export const groupBy = <A>(as: Array<A>, f: (a: A) => string): { [key: string]:
if (r.hasOwnProperty(k)) {
r[k].push(a)
} else {
r[k] = make(a, [])
r[k] = cons(a, [])
}
}
return r
Expand Down
11 changes: 6 additions & 5 deletions test/NonEmptyArray2v.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { showString } from '../src/Show'

describe.only('NonEmptyArray2v', () => {
it('make', () => {
// tslint:disable-next-line: deprecation
assert.deepStrictEqual(make(1, [2]), fromNonEmptyArray([1, 2]))
})

Expand Down Expand Up @@ -304,12 +305,12 @@ describe.only('NonEmptyArray2v', () => {

it('modifyAt', () => {
const double = (n: number): number => n * 2
assert.deepStrictEqual(modifyAt(make<number>(1, []), 1, double), none)
assert.deepStrictEqual(modifyAt(make<number>(1, [2]), 1, double), some(make(1, [4])))
assert.deepStrictEqual(modifyAt(cons(1, []), 1, double), none)
assert.deepStrictEqual(modifyAt(cons(1, [2]), 1, double), some(cons(1, [4])))
})

it('copy', () => {
const nea1 = make<number>(1, [])
const nea1 = cons(1, [])
const nea2 = copy(nea1)
assert.deepStrictEqual(nea2, nea1)
assert.strictEqual(nea2 === nea1, false)
Expand Down Expand Up @@ -403,7 +404,7 @@ describe.only('NonEmptyArray2v', () => {

it('getShow', () => {
const S = getShow(showString)
assert.strictEqual(S.show(make<string>('a', [])), `make("a", [])`)
assert.strictEqual(S.show(make<string>('a', ['b', 'c'])), `make("a", ["b", "c"])`)
assert.strictEqual(S.show(cons('a', [])), `make("a", [])`)
assert.strictEqual(S.show(cons('a', ['b', 'c'])), `make("a", ["b", "c"])`)
})
})

0 comments on commit 93b05b8

Please sign in to comment.