Repository: gcanti/fp-ts
Pull request #821 (2019-04-10 10:48:02)

Create Zipper function fromNonEmptyArray2v.

This PR adds a function which create a `Zipper` from a `NonEmptyArray2v`.


Patch:
diff --git a/docs/modules/Zipper.ts.md b/docs/modules/Zipper.ts.md
index 9641c252..55ac0974 100644
--- a/docs/modules/Zipper.ts.md
+++ b/docs/modules/Zipper.ts.md
@@ -45,6 +45,7 @@ Adapted from
 - [zipper (constant)](#zipper-constant)
 - [fromArray (function)](#fromarray-function)
 - [fromNonEmptyArray (function)](#fromnonemptyarray-function)
+- [fromNonEmptyArray2v (function)](#fromnonemptyarray2v-function)
 - [getMonoid (function)](#getmonoid-function)
 - [getSemigroup (function)](#getsemigroup-function)
 
@@ -305,6 +306,16 @@ export const fromNonEmptyArray = <A>(nea: NonEmptyArray<A>): Zipper<A> => ...
 
 Added in v1.9.0
 
+# fromNonEmptyArray2v (function)
+
+**Signature**
+
+```ts
+export const fromNonEmptyArray2v = <A>(nea: NonEmptyArray2v<A>): Zipper<A> => ...
+```
+
+Added in v1.17.0
+
 # getMonoid (function)
 
 **Signature**
diff --git a/src/Zipper.ts b/src/Zipper.ts
index a3c4faa5..f013b9c3 100644
--- a/src/Zipper.ts
+++ b/src/Zipper.ts
@@ -18,6 +18,7 @@ import { decrement, increment, toString } from './function'
 import { HKT } from './HKT'
 import { Monoid } from './Monoid'
 import { NonEmptyArray } from './NonEmptyArray'
+import { NonEmptyArray as NonEmptyArray2v, tail, head } from './NonEmptyArray2v'
 import { none, Option, some } from './Option'
 import { Semigroup } from './Semigroup'
 import { Traversable2v1 } from './Traversable2v'
@@ -193,6 +194,13 @@ export const fromNonEmptyArray = <A>(nea: NonEmptyArray<A>): Zipper<A> => {
   return new Zipper(empty, nea.head, nea.tail)
 }
 
+/**
+ * @since 1.17.0
+ */
+export const fromNonEmptyArray2v = <A>(nea: NonEmptyArray2v<A>): Zipper<A> => {
+  return new Zipper(empty, head(nea), tail(nea))
+}
+
 const map = <A, B>(fa: Zipper<A>, f: (a: A) => B): Zipper<B> => {
   return fa.map(f)
 }


Test patch:
diff --git a/test/Zipper.ts b/test/Zipper.ts
index c4b3bede..ab0bb19a 100644
--- a/test/Zipper.ts
+++ b/test/Zipper.ts
@@ -3,10 +3,19 @@ import * as F from '../src/Foldable'
 import { identity } from '../src/function'
 import { monoidString, monoidSum } from '../src/Monoid'
 import { NonEmptyArray } from '../src/NonEmptyArray'
+import { fromNonEmptyArray } from '../src/NonEmptyArray2v'
 import { none, option, some } from '../src/Option'
 import { semigroupSum } from '../src/Semigroup'
 import * as T from '../src/Traversable'
-import { fromArray, fromNonEmptyArray, getMonoid, getSemigroup, Zipper, zipper } from '../src/Zipper'
+import {
+  fromArray,
+  fromNonEmptyArray as zipperFromNonEmptyArray,
+  getMonoid,
+  getSemigroup,
+  Zipper,
+  zipper,
+  fromNonEmptyArray2v
+} from '../src/Zipper'
 
 const len = (s: string): number => s.length
 const prepend = (a: string) => (s: string): string => a + s
@@ -126,8 +135,13 @@ describe('Zipper', () => {
   })
 
   it('fromNonEmptyArray', () => {
-    assert.deepStrictEqual(fromNonEmptyArray(new NonEmptyArray(1, [])), new Zipper([], 1, []))
-    assert.deepStrictEqual(fromNonEmptyArray(new NonEmptyArray(1, [2, 3])), new Zipper([], 1, [2, 3]))
+    assert.deepStrictEqual(zipperFromNonEmptyArray(new NonEmptyArray(1, [])), new Zipper([], 1, []))
+    assert.deepStrictEqual(zipperFromNonEmptyArray(new NonEmptyArray(1, [2, 3])), new Zipper([], 1, [2, 3]))
+  })
+
+  it('fromNonEmptyArray2v', () => {
+    assert.deepStrictEqual(fromNonEmptyArray2v(fromNonEmptyArray([1])), new Zipper([], 1, []))
+    assert.deepStrictEqual(fromNonEmptyArray2v(fromNonEmptyArray([1, 2, 3])), new Zipper([], 1, [2, 3]))
   })
 
   it('toString', () => {