Repository: gcanti/fp-ts
Pull request #875 (2019-05-20 14:36:42)

version 1.18.2
- **Polish**
  - fix `NonEmptyArray` definition
- **Deprecation**
  - deprecate `NonEmptyArray.make` in favour of `cons`


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eeb4bced..a3101bc0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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**
diff --git a/docs/modules/NonEmptyArray2v.ts.md b/docs/modules/NonEmptyArray2v.ts.md
index 71a9a30c..dea0771a 100644
--- a/docs/modules/NonEmptyArray2v.ts.md
+++ b/docs/modules/NonEmptyArray2v.ts.md
@@ -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)
@@ -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>
 }
 ```
 
@@ -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**
 
diff --git a/package.json b/package.json
index e90ab925..1421ab5f 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "fp-ts",
-  "version": "1.18.1",
+  "version": "1.18.2",
   "description": "Functional programming in TypeScript",
   "files": [
     "lib",
diff --git a/src/NonEmptyArray2v.ts b/src/NonEmptyArray2v.ts
index 7e53870d..70672e63 100644
--- a/src/NonEmptyArray2v.ts
+++ b/src/NonEmptyArray2v.ts
@@ -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>
 }
 
 /**
@@ -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)
 }
 
 /**
@@ -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
diff --git a/src/Record.ts b/src/Record.ts
index 37fa4e1f..4c2d7f88 100644
--- a/src/Record.ts
+++ b/src/Record.ts
@@ -12,6 +12,12 @@ import { fromEquals, Setoid } from './Setoid'
 import { Unfoldable, Unfoldable1 } from './Unfoldable'
 import { Show, showString } from './Show'
 
+const _hasOwnProperty = Object.prototype.hasOwnProperty
+
+function hasOwnProperty<K extends string, A>(k: K, d: Record<K, A>): boolean {
+  return _hasOwnProperty.call(d, k)
+}
+
 /**
  * @since 1.17.0
  */
@@ -118,7 +124,7 @@ export function remove<KS extends string, K extends string, A>(
 ): Record<string extends K ? string : Exclude<KS, K>, A>
 export function remove<A>(k: string, d: Record<string, A>): Record<string, A>
 export function remove<A>(k: string, d: Record<string, A>): Record<string, A> {
-  if (!d.hasOwnProperty(k)) {
+  if (!hasOwnProperty(k, d)) {
     return d
   }
   const r = Object.assign({}, d)
@@ -143,7 +149,7 @@ export const pop = <A>(k: string, d: Record<string, A>): Option<[A, Record<strin
  */
 export const isSubrecord = <A>(S: Setoid<A>) => (d1: Record<string, A>, d2: Record<string, A>): boolean => {
   for (let k in d1) {
-    if (!d2.hasOwnProperty(k) || !S.equals(d1[k], d2[k])) {
+    if (!hasOwnProperty(k, d2) || !S.equals(d1[k], d2[k])) {
       return false
     }
   }
@@ -193,7 +199,7 @@ export function getMonoid<A>(S: Semigroup<A>): Monoid<Record<string, A>> {
  * @since 1.10.0
  */
 export const lookup = <A>(key: string, fa: Record<string, A>): Option<A> => {
-  return fa.hasOwnProperty(key) ? optionSome(fa[key]) : none
+  return hasOwnProperty(key, fa) ? optionSome(fa[key]) : none
 }
 
 /**
@@ -645,7 +651,7 @@ export function filterWithKey<A>(fa: Record<string, A>, p: (key: string, a: A) =
   const r: Record<string, A> = {}
   let changed = false
   for (const key in fa) {
-    if (fa.hasOwnProperty(key)) {
+    if (hasOwnProperty(key, fa)) {
       const a = fa[key]
       if (p(key, a)) {
         r[key] = a
@@ -682,7 +688,7 @@ export function fromFoldable<F>(
 ): <A>(ta: HKT<F, [string, A]>, onConflict: (existing: A, a: A) => A) => Record<string, A> {
   return <A>(ta: HKT<F, [string, A]>, f: (existing: A, a: A) => A) => {
     return F.reduce<[string, A], Record<string, A>>(ta, {}, (b, [k, a]) => {
-      b[k] = b.hasOwnProperty(k) ? f(b[k], a) : a
+      b[k] = hasOwnProperty(k, b) ? f(b[k], a) : a
       return b
     })
   }
@@ -750,7 +756,7 @@ export function fromFoldableMap<F, B>(
   return <A>(ta: HKT<F, A>, f: (a: A) => [string, B]) => {
     return F.reduce<A, Record<string, B>>(ta, {}, (r, a) => {
       const [k, b] = f(a)
-      r[k] = r.hasOwnProperty(k) ? M.concat(r[k], b) : b
+      r[k] = hasOwnProperty(k, r) ? M.concat(r[k], b) : b
       return r
     })
   }


Test patch:
diff --git a/test/NonEmptyArray2v.ts b/test/NonEmptyArray2v.ts
index 5608a61a..f5eb49e2 100644
--- a/test/NonEmptyArray2v.ts
+++ b/test/NonEmptyArray2v.ts
@@ -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]))
   })
 
@@ -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)
@@ -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"])`)
   })
 })