Repository: gcanti/fp-ts
Pull request #868 (2019-05-13 09:40:36)

version 1.18.0


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4a4366a5..6e4001a7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,11 @@
 **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.0
+
+- **New Feature**
+  - add `absurd` function, closes #847 (@gcanti)
+
 # 1.17.4
 
 - **Bug Fix**
diff --git a/docs/modules/Record.ts.md b/docs/modules/Record.ts.md
index 7a981c52..d2b8ea82 100644
--- a/docs/modules/Record.ts.md
+++ b/docs/modules/Record.ts.md
@@ -85,6 +85,8 @@ Added in v1.10.0
 
 # collect (function)
 
+Map a record into an array
+
 **Signature**
 
 ```ts
@@ -92,6 +94,18 @@ export function collect<K extends string, A, B>(d: Record<K, A>, f: (k: K, a: A)
 export function collect<A, B>(d: Record<string, A>, f: (k: string, a: A) => B): Array<B> { ... }
 ```
 
+**Example**
+
+```ts
+import { collect } from 'fp-ts/lib/Record'
+
+const ob: { a: string; b: boolean } = { a: 'foo', b: false }
+assert.deepStrictEqual(collect(ob, (key, val) => ({ key: key, value: val })), [
+  { key: 'a', value: 'foo' },
+  { key: 'b', value: false }
+])
+```
+
 Added in v1.10.0
 
 # compact (function)
@@ -419,6 +433,8 @@ Added in v1.10.0
 
 # map (function)
 
+Map a record passing the values to the iterating function
+
 **Signature**
 
 ```ts
@@ -430,6 +446,8 @@ Added in v1.10.0
 
 # mapWithKey (function)
 
+Map a record passing the keys to the iterating function
+
 **Signature**
 
 ```ts
@@ -551,12 +569,24 @@ Added in v1.10.0
 
 # reduce (function)
 
+Reduce object by iterating over it's values.
+
 **Signature**
 
 ```ts
 export const reduce = <A, B>(fa: Record<string, A>, b: B, f: (b: B, a: A) => B): B => ...
 ```
 
+**Example**
+
+```ts
+import { reduce } from 'fp-ts/lib/Record'
+
+const joinAllVals = (ob: { [k: string]: string }) => reduce(ob, '', (acc, val) => acc + val)
+
+assert.deepStrictEqual(joinAllVals({ a: 'foo', b: 'bar' }), 'foobar')
+```
+
 Added in v1.10.0
 
 # reduceWithKey (function)
diff --git a/docs/modules/function.ts.md b/docs/modules/function.ts.md
index e5fa5682..7225e5f9 100644
--- a/docs/modules/function.ts.md
+++ b/docs/modules/function.ts.md
@@ -35,6 +35,7 @@ parent: Modules
 - [Refinement (type alias)](#refinement-type-alias)
 - [phantom (constant)](#phantom-constant)
 - [unsafeCoerce (constant)](#unsafecoerce-constant)
+- [absurd (function)](#absurd-function)
 - [and (function)](#and-function)
 - [apply (function)](#apply-function)
 - [applyFlipped (function)](#applyflipped-function)
@@ -301,6 +302,16 @@ export const unsafeCoerce: <A, B>(a: A) => B = ...
 
 Added in v1.0.0
 
+# absurd (function)
+
+**Signature**
+
+```ts
+export function absurd<A>(_: never): A { ... }
+```
+
+Added in v1.18.0
+
 # and (function)
 
 **Signature**
diff --git a/package-lock.json b/package-lock.json
index 315970ab..58d73af7 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "fp-ts",
-  "version": "1.17.3",
+  "version": "1.17.4",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
diff --git a/package.json b/package.json
index 3476a259..ec16527b 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "fp-ts",
-  "version": "1.17.4",
+  "version": "1.18.0",
   "description": "Functional programming in TypeScript",
   "files": [
     "lib",
diff --git a/src/Record.ts b/src/Record.ts
index 9d45bf39..37fa4e1f 100644
--- a/src/Record.ts
+++ b/src/Record.ts
@@ -241,10 +241,11 @@ export function map<A, B>(fa: Record<string, A>, f: (a: A) => B): Record<string,
  * @since 1.10.0
  *
  * @example
- * import {reduce} from 'fp-ts/lib/Record'
+ * import { reduce } from 'fp-ts/lib/Record'
  *
- * const joinAllVals = (ob: {[k: string]: string}) => reduce(ob, (acc, val) => acc + val, '')
- * assert.deepStrictEqual(joinAllVals({a: 'foo', b: 'bar'}), 'foobar'))
+ * const joinAllVals = (ob: {[k: string]: string}) => reduce(ob, '', (acc, val) => acc + val)
+ *
+ * assert.deepStrictEqual(joinAllVals({a: 'foo', b: 'bar'}), 'foobar')
  */
 export const reduce = <A, B>(fa: Record<string, A>, b: B, f: (b: B, a: A) => B): B => {
   return reduceWithKey(fa, b, (_, b, a) => f(b, a))
diff --git a/src/function.ts b/src/function.ts
index 429967dd..909d0021 100644
--- a/src/function.ts
+++ b/src/function.ts
@@ -424,3 +424,10 @@ export const increment = (n: number): number => {
 export const decrement = (n: number): number => {
   return n - 1
 }
+
+/**
+ * @since 1.18.0
+ */
+export function absurd<A>(_: never): A {
+  throw new Error('Called `absurd` function which should be uncallable')
+}


Test patch:
diff --git a/test/function.ts b/test/function.ts
index dd63cf75..12e9fc64 100644
--- a/test/function.ts
+++ b/test/function.ts
@@ -18,7 +18,8 @@ import {
   constUndefined,
   toString,
   constVoid,
-  tupleCurried
+  tupleCurried,
+  absurd
 } from '../src/function'
 
 const f = (n: number) => n + 1
@@ -325,4 +326,8 @@ describe('function', () => {
     // tslint:disable-next-line: deprecation
     assert.deepStrictEqual(tupleCurried(1)('a'), [1, 'a'])
   })
+
+  it('absurd', () => {
+    assert.throws(() => absurd<string>((null as any) as never))
+  })
 })