Repository: gcanti/fp-ts (ts)

Issue:
TaskEither.tryCatch should either try/catch or be renamed
## 🚀 Feature request

### Current Behavior

`TE.tryCatch` only handles promises which have been rejected.

### Desired Behavior

It should have the same semantics as a javascript `try`/`catch` construct. 

Or it should be deprecated and renamed to something not misleading, such as `TE.catchRejectedPromise`

<!-- A clear and concise description of what you want to happen.  -->

### Suggested Solution

Wrapping the code in a try/catch, or using an async function and try/catch block.

### Who does this impact? Who is this for?

All users.

### Describe alternatives you've considered

Wrapping `TE.tryCatch` in a try/catch.

### Additional context

I did read the docs where it said that `r` cannot throw.

### Your environment

<!-- PLEASE FILL THIS OUT -->

| Software   | Version(s) |
| ---------- | ---------- |
| fp-ts      |   2.11.8         |
| TypeScript |   4.5.5         |


Pull request description:
try/catch in tryCatch
This reopens and updates #1001 to allow `f` in `TaskEither` and `TaskOption`'s `tryCatch`/`tryCatchK` to throw an error (as opposed to only returning a resolved/rejected promise).

Fixes #1672.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 963d0340..b5c831f9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,11 @@
 **Note**: A feature tagged as Experimental is in a
 high state of flux, you're at risk of it changing without notice.
 
+# 2.11.9
+
+- **Polish**
+  - add `Refinement` overload to 'every' functions, #1681 (@mlegenhausen)
+
 # 2.11.8
 
 - **Polish**
diff --git a/docs/ecosystem.md b/docs/ecosystem.md
index eab5e012..a5e0f4a6 100644
--- a/docs/ecosystem.md
+++ b/docs/ecosystem.md
@@ -23,6 +23,7 @@ has_toc: false
 - [spectacles-ts](https://github.com/anthonyjoeseph/spectacles-ts/) - A simple facade built on top of monocle-ts (autocompletes possible combinators)
 - [newtype-ts](https://github.com/gcanti/newtype-ts) - Implementation of newtypes in TypeScript
 - [logging-ts](https://github.com/gcanti/logging-ts) - Composable loggers for TypeScript
+- [logger-fp-ts](https://github.com/thewilkybarkid/logger-fp-ts) - Logger built on top of logging-ts
 - [fp-ts-routing](https://github.com/gcanti/fp-ts-routing) - A type-safe bidirectional routing library for TypeScript
 - [parser-ts](https://github.com/gcanti/parser-ts) - String parser combinators for TypeScript
 - [remote-data-ts](https://github.com/devex-web-frontend/remote-data-ts) - RemoteData type (check [this article](https://medium.com/@gcanti/slaying-a-ui-antipattern-with-flow-5eed0cfb627b))
diff --git a/docs/guides/HKT.md b/docs/guides/HKT.md
index 4be01d58..1c6868e4 100644
--- a/docs/guides/HKT.md
+++ b/docs/guides/HKT.md
@@ -21,13 +21,13 @@ Let's see how to add an instance of the `Functor` type class for `Identity`
 ```ts
 // Identity.ts
 
-import { Functor1 } from 'fp-ts/lib/Functor'
+import { Functor1 } from 'fp-ts/Functor'
 
 export const URI = 'Identity'
 
 export type URI = typeof URI
 
-declare module 'fp-ts/lib/HKT' {
+declare module 'fp-ts/HKT' {
   interface URItoKind<A> {
     readonly Identity: Identity<A>
   }
@@ -36,7 +36,7 @@ declare module 'fp-ts/lib/HKT' {
 export type Identity<A> = A
 
 // Functor instance
-export const identity: Functor1<URI> = {
+export const Functor: Functor1<URI> = {
   URI,
   map: (ma, f) => f(ma)
 }
@@ -45,7 +45,7 @@ export const identity: Functor1<URI> = {
 Here's the definition of `Functor1`
 
 ```ts
-// fp-ts/lib/Functor.ts
+// fp-ts/Functor.ts
 
 export interface Functor1<F extends URIS> {
   readonly URI: F
@@ -58,7 +58,7 @@ So what's `URItoKind`, `URIS` and `Kind`?
 `URItoKind` is type-level map, it maps a `URI` to a concrete data type, and is populated using the [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html) feature
 
 ```ts
-// fp-ts/lib/HKT.ts
+// fp-ts/HKT.ts
 
 export interface URItoKind<A> {}
 ```
@@ -66,7 +66,7 @@ export interface URItoKind<A> {}
 ```ts
 // Identity.ts
 
-declare module 'fp-ts/lib/HKT' {
+declare module 'fp-ts/HKT' {
   interface URItoKind<A> {
     readonly Identity: Identity<A> // maps the key "Identity" to the type `Identity`
   }
@@ -87,13 +87,13 @@ Example: `Either`
 ```ts
 // Either.ts
 
-import { Functor2 } from 'fp-ts/lib/Functor'
+import { Functor2 } from 'fp-ts/Functor'
 
 export const URI = 'Either'
 
 export type URI = typeof URI
 
-declare module 'fp-ts/lib/HKT' {
+declare module 'fp-ts/HKT' {
   interface URItoKind2<E, A> {
     readonly Either: Either<E, A>
   }
@@ -111,8 +111,10 @@ export interface Right<A> {
 
 export type Either<E, A> = Left<E> | Right<A>
 
+export const right = <A, E = never>(a: A): Either<E, A> => ({ _tag: 'Right', right: a })
+
 // Functor instance
-export const either: Functor2<URI> = {
+export const Functor: Functor2<URI> = {
   URI,
   map: (ma, f) => (ma._tag === 'Left' ? ma : right(f(ma.right)))
 }
@@ -121,7 +123,7 @@ export const either: Functor2<URI> = {
 And here's the definition of `Functor2`
 
 ```ts
-// fp-ts/lib/Functor.ts
+// fp-ts/Functor.ts
 
 export interface Functor2<F extends URIS2> {
   readonly URI: F
@@ -134,7 +136,7 @@ export interface Functor2<F extends URIS2> {
 Let's see how to type `lift`
 
 ```ts
-import { HKT } from 'fp-ts/lib/HKT'
+import { HKT } from 'fp-ts/HKT'
 
 export function lift<F>(F: Functor<F>): <A, B>(f: (a: A) => B) => (fa: HKT<F, A>) => HKT<F, B> {
   return (f) => (fa) => F.map(fa, f)
@@ -144,7 +146,7 @@ export function lift<F>(F: Functor<F>): <A, B>(f: (a: A) => B) => (fa: HKT<F, A>
 Here's the definition of `HKT`
 
 ```ts
-// fp-ts/lib/HKT.ts
+// fp-ts/HKT.ts
 
 export interface HKT<URI, A> {
   readonly _URI: URI
@@ -154,7 +156,7 @@ export interface HKT<URI, A> {
 
 The `HKT` type represents a type constructor of kind `* -> *`.
 
-There are other `HKT<n>` types defined in the `fp-ts/lib/HKT.ts`, one for each kind (up to four):
+There are other `HKT<n>` types defined in the `fp-ts/HKT.ts`, one for each kind (up to four):
 
 - `HKT2` for type constructors of kind `* -> * -> *`
 - `HKT3` for type constructors of kind `* -> * -> * -> *`
diff --git a/docs/guides/code-conventions.md b/docs/guides/code-conventions.md
index 821521c6..20f50ee7 100644
--- a/docs/guides/code-conventions.md
+++ b/docs/guides/code-conventions.md
@@ -14,7 +14,10 @@ nav_order: 1
 - [Module structure](#module-structure)
 - [FAQ](#faq)
   - [What a `C` suffix means, e.g. `Functor2C` vs `Functor2`](#what-a-c-suffix-means-eg-functor2c-vs-functor2)
+  - [What an `E` suffix means, e.g. `matchE`](#what-an-e-suffix-means-eg-matche)
+  - [What a `K` suffix means, e.g. `fromEitherK` or `chainEitherK`](#what-a-k-suffix-means-eg-fromeitherk-or-chaineitherk)
   - [What a `T` suffix means, e.g. `sequenceT`](#what-a-t-suffix-means-eg-sequencet)
+  - [What a `W` suffix means, e.g. `chainW` or `chainEitherKW`](#what-a-w-suffix-means-eg-chainw-or-chaineitherkw)
 
 <!-- END doctoc generated TOC please keep comment here to allow auto update -->
 
@@ -86,11 +89,27 @@ For example, `Validation` admits a `Functor` instance only if you provide a `Sem
 const getFunctor = <E>(S: Semigroup<E>): Functor2C<"Validation", E> = { ... }
 ```
 
-### What a `T` suffix means, e.g. `sequenceT`
+### What an `E` suffix means, e.g. `matchE`
 
-in `sequenceT` means *T*uple, I borrowed the name from the corresponding [Haskell function](http://hackage.haskell.org/package/tuple-0.3.0.2/docs/Data-Tuple-Sequence.html)
+`E` means *E*ffect. An example of its use is in the `matchE` destructor on monad transformers like `TaskOption` or `ReaderTaskEither`.
 
-However usually it means *T*ransformer like in "monad transformers" (e.g. `OptionT`, `EitherT`, `ReaderT`, `StateT`)
+**Example**
+
+Both of these destructions result in a `Task<number>`, but in the case of `matchE` an effect (in this case in the form of a `Task`) is returned on match.
+
+```ts
+import * as T from "fp-ts/Task";
+import * as TO from "fp-ts/TaskOption";
+import { pipe } from "fp-ts/function";
+
+const value = TO.of("hello");
+
+// T.Task<number>
+pipe(value, TO.match(() => 0, (str) => str.length));
+
+// T.Task<number>
+pipe(value, TO.matchE(() => T.of(0), (str) => T.of(str.length)));
+```
 
 ### What a `K` suffix means, e.g. `fromEitherK` or `chainEitherK`
 
@@ -148,6 +167,12 @@ pipe(input, IE.chain(IE.fromEitherK(parse)))() // left(new Error('cannot decode
 pipe(input, IE.chainEitherK(parse))() // left(new Error('cannot decode "foo" to number'))
 ```
 
+### What a `T` suffix means, e.g. `sequenceT`
+
+in `sequenceT` means *T*uple, I borrowed the name from the corresponding [Haskell function](http://hackage.haskell.org/package/tuple-0.3.0.2/docs/Data-Tuple-Sequence.html)
+
+However usually it means *T*ransformer like in "monad transformers" (e.g. `OptionT`, `EitherT`, `ReaderT`, `StateT`)
+
 ### What a `W` suffix means, e.g. `chainW` or `chainEitherKW`
 
 `W` means *W*iden. Functions that end with `W` are able to aggregate errors into a union (for `Either` based data types) or environments into an intersection (for `Reader` based data types).
diff --git a/docs/learning-resources.md b/docs/learning-resources.md
index 8ab7c5cf..62355279 100644
--- a/docs/learning-resources.md
+++ b/docs/learning-resources.md
@@ -9,7 +9,7 @@ has_toc: false
 # Learning Resources
 
 - [Mostly adequate guide to FP](https://github.com/MostlyAdequate/mostly-adequate-guide) by [@DrBoolean](https://github.com/DrBoolean)
-- [The State monad](https://paulgray.net/the-state-monad/)
+- [The State monad](https://paulgray.net/the-state-monad/) by Paul Gray
 
 ## Getting started with fp-ts series
 
@@ -44,7 +44,14 @@ has_toc: false
 ## Community documentation
 
 - [fp-ts recipes](https://grossbart.github.io/fp-ts-recipes/) – A collection of practical recipes for working with `fp-ts`
+- [Mostly adequate guide to FP-TS](https://cjonas.gitbook.io/mostly-adequate-fp-ts/) partial rewrite by ChuckJonas
+- [Book: Introduction to Functional Programming by Giulio Canti](https://github.com/enricopolanski/functional-programming) English translation by Enrico Polanski
+
 
 ## Community Blog Posts
 
-[When An Error Is Not An Exception](https://dev.to/vncz/forewords-and-domain-model-1p13) — How we rewrote the core of Prism to make it almost totally functional
+- [When An Error Is Not An Exception](https://dev.to/vncz/forewords-and-domain-model-1p13) — How we rewrote the core of Prism to make it almost totally functional
+- [Introduction series to FP-TS](https://ybogomolov.me/01-higher-kinded-types/) by Yuriy Bogomolov
+- [The ReaderTaskMonad](https://andywhite.xyz/posts/) by Andy White
+- [FP-TS for HTTP-requests](https://kimmosaaskilahti.fi/blog/2019-08-29-fp-ts/) by Kimmo Sasskilahti
+- [Basic introduction to FP-TS](https://davetayls.me/blog/2018/06/09/fp-ts-02-handling-error-cases) by Dave Tayls
diff --git a/docs/modules/Array.ts.md b/docs/modules/Array.ts.md
index eddffd87..ba903881 100644
--- a/docs/modules/Array.ts.md
+++ b/docs/modules/Array.ts.md
@@ -3313,7 +3313,10 @@ Added in v2.0.0
 **Signature**
 
 ```ts
-export declare const every: <A>(predicate: Predicate<A>) => (as: A[]) => boolean
+export declare const every: {
+  <A, B extends A>(refinement: Refinement<A, B>): Refinement<A[], B[]>
+  <A>(predicate: Predicate<A>): Predicate<A[]>
+}
 ```
 
 **Example**
diff --git a/docs/modules/ReadonlyArray.ts.md b/docs/modules/ReadonlyArray.ts.md
index 7272f0d0..4df77327 100644
--- a/docs/modules/ReadonlyArray.ts.md
+++ b/docs/modules/ReadonlyArray.ts.md
@@ -2433,7 +2433,10 @@ Check if a predicate holds true for every array member.
 **Signature**
 
 ```ts
-export declare const every: <A>(predicate: Predicate<A>) => (as: readonly A[]) => boolean
+export declare function every<A, B extends A>(
+  refinement: Refinement<A, B>
+): Refinement<ReadonlyArray<A>, ReadonlyArray<B>>
+export declare function every<A>(predicate: Predicate<A>): Predicate<ReadonlyArray<A>>
 ```
 
 **Example**
diff --git a/docs/modules/ReadonlyRecord.ts.md b/docs/modules/ReadonlyRecord.ts.md
index 0466dab4..6471da72 100644
--- a/docs/modules/ReadonlyRecord.ts.md
+++ b/docs/modules/ReadonlyRecord.ts.md
@@ -1235,7 +1235,10 @@ Test if every value in a `ReadonlyRecord` satisfies the predicate.
 **Signature**
 
 ```ts
-export declare function every<A>(predicate: Predicate<A>): (r: ReadonlyRecord<string, A>) => boolean
+export declare function every<A, B extends A>(
+  refinement: Refinement<A, B>
+): Refinement<ReadonlyRecord<string, A>, ReadonlyRecord<string, B>>
+export declare function every<A>(predicate: Predicate<A>): Predicate<ReadonlyRecord<string, A>>
 ```
 
 **Example**
diff --git a/docs/modules/ReadonlySet.ts.md b/docs/modules/ReadonlySet.ts.md
index 83c267ff..522bc59d 100644
--- a/docs/modules/ReadonlySet.ts.md
+++ b/docs/modules/ReadonlySet.ts.md
@@ -392,7 +392,8 @@ Added in v2.5.0
 **Signature**
 
 ```ts
-export declare const every: <A>(predicate: Predicate<A>) => (set: ReadonlySet<A>) => boolean
+export declare function every<A, B extends A>(refinement: Refinement<A, B>): Refinement<ReadonlySet<A>, ReadonlySet<B>>
+export declare function every<A>(predicate: Predicate<A>): Predicate<ReadonlySet<A>>
 ```
 
 Added in v2.5.0
diff --git a/docs/modules/Record.ts.md b/docs/modules/Record.ts.md
index c207c7fd..e3a1660d 100644
--- a/docs/modules/Record.ts.md
+++ b/docs/modules/Record.ts.md
@@ -995,7 +995,10 @@ Test if every value in a `Record` satisfies the predicate.
 **Signature**
 
 ```ts
-export declare const every: <A>(predicate: Predicate<A>) => (r: Record<string, A>) => boolean
+export declare const every: {
+  <A, B extends A>(refinement: Refinement<A, B>): Refinement<Record<string, A>, Record<string, B>>
+  <A>(predicate: Predicate<A>): Predicate<Record<string, A>>
+}
 ```
 
 **Example**
diff --git a/docs/modules/Set.ts.md b/docs/modules/Set.ts.md
index 0795d6b7..0307552a 100644
--- a/docs/modules/Set.ts.md
+++ b/docs/modules/Set.ts.md
@@ -328,7 +328,10 @@ Added in v2.0.0
 **Signature**
 
 ```ts
-export declare const every: <A>(predicate: Predicate<A>) => (set: Set<A>) => boolean
+export declare const every: {
+  <A, B extends A>(refinement: Refinement<A, B>): Refinement<Set<A>, Set<B>>
+  <A>(predicate: Predicate<A>): Predicate<Set<A>>
+}
 ```
 
 Added in v2.0.0
diff --git a/docs/modules/TaskEither.ts.md b/docs/modules/TaskEither.ts.md
index 4482de60..cef87a3f 100644
--- a/docs/modules/TaskEither.ts.md
+++ b/docs/modules/TaskEither.ts.md
@@ -1245,8 +1245,6 @@ Added in v2.10.0
 
 Transforms a `Promise` that may reject to a `Promise` that never rejects and returns an `Either` instead.
 
-Note: `f` should never `throw` errors, they are not caught.
-
 See also [`tryCatchK`](#trycatchk).
 
 **Signature**
diff --git a/docs/modules/TaskOption.ts.md b/docs/modules/TaskOption.ts.md
index 738f0a35..ea752686 100644
--- a/docs/modules/TaskOption.ts.md
+++ b/docs/modules/TaskOption.ts.md
@@ -808,8 +808,6 @@ Added in v2.10.0
 
 Transforms a `Promise` that may reject to a `Promise` that never rejects and returns an `Option` instead.
 
-Note: `f` should never `throw` errors, they are not caught.
-
 See also [`tryCatchK`](#trycatchk).
 
 **Signature**
diff --git a/docs/modules/pipeable.ts.md b/docs/modules/pipeable.ts.md
index 9b726e94..351bed30 100644
--- a/docs/modules/pipeable.ts.md
+++ b/docs/modules/pipeable.ts.md
@@ -1982,7 +1982,7 @@ Added in v2.0.0
 
 ## ~~pipe~~
 
-Use [`pipe`](https://gcanti.github.io/fp-ts/modules/function.ts.html#flow) from `function` module instead.
+Use [`pipe`](https://gcanti.github.io/fp-ts/modules/function.ts.html#pipe) from `function` module instead.
 
 **Signature**
 
diff --git a/examples/fp-ts-to-the-max-I.ts b/examples/fp-ts-to-the-max-I.ts
index 9d9e4185..7a3bc579 100644
--- a/examples/fp-ts-to-the-max-I.ts
+++ b/examples/fp-ts-to-the-max-I.ts
@@ -1,9 +1,7 @@
 import { createInterface } from 'readline'
-import { sequenceS } from '../src/Apply'
 import { log } from '../src/Console'
-import { flow } from '../src/function'
+import { flow, pipe } from '../src/function'
 import * as O from '../src/Option'
-import { pipe } from '../src/pipeable'
 import { randomInt } from '../src/Random'
 import * as T from '../src/Task'
 
@@ -64,15 +62,11 @@ function shouldContinue(name: string): T.Task<boolean> {
   )
 }
 
-// run `n` tasks in parallel
-const ado = sequenceS(T.task)
-
 function gameLoop(name: string): T.Task<void> {
   return pipe(
-    ado({
-      secret: random,
-      guess: ask(`Dear ${name}, please guess a number from 1 to 5`)
-    }),
+    T.Do,
+    T.apS('secret', random),
+    T.apS('guess', ask(`Dear ${name}, please guess a number from 1 to 5`)),
     T.chain(({ secret, guess }) =>
       pipe(
         parse(guess),
diff --git a/examples/fp-ts-to-the-max-II.ts b/examples/fp-ts-to-the-max-II.ts
index 99631769..1ac27e38 100644
--- a/examples/fp-ts-to-the-max-II.ts
+++ b/examples/fp-ts-to-the-max-II.ts
@@ -4,27 +4,27 @@ import * as O from '../src/Option'
 import { randomInt } from '../src/Random'
 import * as T from '../src/Task'
 import { createInterface } from 'readline'
-import { State, state } from '../src/State'
+import * as S from '../src/State'
 import { Monad1 } from '../src/Monad'
-import { flow } from '../src/function'
-import { pipe, pipeable } from '../src/pipeable'
-import { sequenceS } from '../src/Apply'
+import { flow, pipe } from '../src/function'
+import { apS as apS_ } from '../src/Apply'
+import { chainFirst as chainFirst_ } from '../src/Chain'
 
 //
 // type classes
 //
 
 interface Program<F extends URIS> extends Monad1<F> {
-  finish: <A>(a: A) => Kind<F, A>
+  readonly finish: <A>(a: A) => Kind<F, A>
 }
 
 interface Console<F extends URIS> {
-  putStrLn: (message: string) => Kind<F, void>
-  getStrLn: Kind<F, string>
+  readonly putStrLn: (message: string) => Kind<F, void>
+  readonly getStrLn: Kind<F, string>
 }
 
 interface Random<F extends URIS> {
-  nextInt: (upper: number) => Kind<F, number>
+  readonly nextInt: (upper: number) => Kind<F, number>
 }
 
 interface Main<F extends URIS> extends Program<F>, Console<F>, Random<F> {}
@@ -34,7 +34,7 @@ interface Main<F extends URIS> extends Program<F>, Console<F>, Random<F> {}
 //
 
 const programTask: Program<T.URI> = {
-  ...T.task,
+  ...T.Monad,
   finish: T.of
 }
 
@@ -74,10 +74,10 @@ function parse(s: string): O.Option<number> {
 }
 
 function main<F extends URIS>(F: Main<F>): Kind<F, void> {
-  // run `n` tasks in parallel
-  const ado = sequenceS(F)
-
-  const { chain, chainFirst } = pipeable(F)
+  const chain = <A, B>(f: (a: A) => Kind<F, B>) => (ma: Kind<F, A>): Kind<F, B> => F.chain(ma, f)
+  const Do: Kind<F, {}> = F.of({})
+  const apS = apS_(F)
+  const chainFirst = chainFirst_(F)
 
   // ask something and get the answer
   const ask = (question: string): Kind<F, string> =>
@@ -104,10 +104,9 @@ function main<F extends URIS>(F: Main<F>): Kind<F, void> {
 
   const gameLoop = (name: string): Kind<F, void> => {
     return pipe(
-      ado({
-        secret: F.nextInt(5),
-        guess: ask(`Dear ${name}, please guess a number from 1 to 5`)
-      }),
+      Do,
+      apS('secret', F.nextInt(5)),
+      apS('guess', ask(`Dear ${name}, please guess a number from 1 to 5`)),
       chain(({ secret, guess }) =>
         pipe(
           parse(guess),
@@ -139,18 +138,22 @@ export const mainTask = main({
 })
 
 // tslint:disable-next-line: no-floating-promises
-// mainTask.run()
+// mainTask()
 
 //
 // tests
 //
 
-import { dropLeft, snoc } from '../src/Array'
+import { dropLeft, append } from '../src/ReadonlyArray'
 
 class TestData {
-  constructor(readonly input: Array<string>, readonly output: Array<string>, readonly nums: Array<number>) {}
+  constructor(
+    readonly input: ReadonlyArray<string>,
+    readonly output: ReadonlyArray<string>,
+    readonly nums: ReadonlyArray<number>
+  ) {}
   putStrLn(message: string): [void, TestData] {
-    return [undefined, new TestData(this.input, snoc(this.output, message), this.nums)]
+    return [undefined, new TestData(this.input, pipe(this.output, append(message)), this.nums)]
   }
   getStrLn(): [string, TestData] {
     return [this.input[0], new TestData(dropLeft(1)(this.input), this.output, this.nums)]
@@ -166,20 +169,17 @@ type URI = typeof URI
 
 declare module '../src/HKT' {
   interface URItoKind<A> {
-    Test: Test<A>
+    readonly Test: Test<A>
   }
 }
 
-interface Test<A> extends State<TestData, A> {}
+interface Test<A> extends S.State<TestData, A> {}
 
 const of = <A>(a: A): Test<A> => (data) => [a, data]
 
 const programTest: Program<URI> = {
+  ...S.Monad,
   URI,
-  map: state.map,
-  of: state.of,
-  ap: state.ap,
-  chain: state.chain,
   finish: of
 }
 
diff --git a/package-lock.json b/package-lock.json
index dd6274cb..9cf6fb65 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "fp-ts",
-  "version": "2.11.0-rc.1",
+  "version": "2.11.9",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
@@ -2350,7 +2350,7 @@
       }
     },
     "dtslint": {
-      "version": "github:gcanti/dtslint#824af7cf7780df9840b87d126835a40da740c064",
+      "version": "github:gcanti/dtslint#2c3c3487e7650d6ca90c2877dbbd7c4c08360d0d",
       "from": "github:gcanti/dtslint",
       "dev": true,
       "requires": {
@@ -2358,7 +2358,7 @@
         "parsimmon": "^1.12.0",
         "strip-json-comments": "^2.0.1",
         "tslint": "^5.12.0",
-        "typescript": "^4.3.0-dev.20210429"
+        "typescript": "^4.6.2"
       },
       "dependencies": {
         "ansi-styles": {
@@ -2433,9 +2433,9 @@
           }
         },
         "typescript": {
-          "version": "4.3.0-dev.20210429",
-          "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.0-dev.20210429.tgz",
-          "integrity": "sha512-rBkCCg6odkGs1Xc2pKHhjwCCYm2wrx6LvqgbWAquRg7yRVFz6lNtRLfqc+q0Oc5N9BjnlcyWTAi+mqOZzIZUDA==",
+          "version": "4.6.2",
+          "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.2.tgz",
+          "integrity": "sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==",
           "dev": true
         }
       }
@@ -5278,18 +5278,18 @@
       }
     },
     "mkdirp": {
-      "version": "0.5.5",
-      "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
-      "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
+      "version": "0.5.6",
+      "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz",
+      "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==",
       "dev": true,
       "requires": {
-        "minimist": "^1.2.5"
+        "minimist": "^1.2.6"
       },
       "dependencies": {
         "minimist": {
-          "version": "1.2.5",
-          "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
-          "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
+          "version": "1.2.6",
+          "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
+          "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
           "dev": true
         }
       }
@@ -5671,9 +5671,9 @@
       "dev": true
     },
     "parsimmon": {
-      "version": "1.17.0",
-      "resolved": "https://registry.npmjs.org/parsimmon/-/parsimmon-1.17.0.tgz",
-      "integrity": "sha512-gp5yNYs0Lyv5Mp6hj+JMzsHaM4Mel0WuK2iHYKX32ActYAQdsSq+t4nVsqlOpUCiMYdTX1wFISLvugrAl9harg==",
+      "version": "1.18.1",
+      "resolved": "https://registry.npmjs.org/parsimmon/-/parsimmon-1.18.1.tgz",
+      "integrity": "sha512-u7p959wLfGAhJpSDJVYXoyMCXWYwHia78HhRBWqk7AIbxdmlrfdp5wX0l3xv/iTSH5HvhN9K7o26hwwpgS5Nmw==",
       "dev": true
     },
     "pascalcase": {
diff --git a/package.json b/package.json
index 2494a763..ad74bbbb 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "fp-ts",
-  "version": "2.11.8",
+  "version": "2.11.9",
   "description": "Functional programming in TypeScript",
   "main": "lib/index.js",
   "module": "es6/index.js",
diff --git a/src/Array.ts b/src/Array.ts
index 1ad8387a..919043e5 100644
--- a/src/Array.ts
+++ b/src/Array.ts
@@ -2863,7 +2863,10 @@ export const unsafeDeleteAt = <A>(i: number, as: Array<A>): Array<A> => {
  *
  * @since 2.9.0
  */
-export const every: <A>(predicate: Predicate<A>) => (as: Array<A>) => boolean = RA.every
+export const every: {
+  <A, B extends A>(refinement: Refinement<A, B>): Refinement<Array<A>, Array<B>>
+  <A>(predicate: Predicate<A>): Predicate<Array<A>>
+} = RA.every as any
 
 /**
  * `some` tells if the provided predicate holds true at least for one element in the `Array`.
diff --git a/src/ReadonlyArray.ts b/src/ReadonlyArray.ts
index 3ec4c595..3a06c93c 100644
--- a/src/ReadonlyArray.ts
+++ b/src/ReadonlyArray.ts
@@ -2455,7 +2455,11 @@ export const empty: ReadonlyArray<never> = RNEA.empty
  *
  * @since 2.9.0
  */
-export const every = <A>(predicate: Predicate<A>) => (as: ReadonlyArray<A>): boolean => as.every(predicate)
+export function every<A, B extends A>(refinement: Refinement<A, B>): Refinement<ReadonlyArray<A>, ReadonlyArray<B>>
+export function every<A>(predicate: Predicate<A>): Predicate<ReadonlyArray<A>>
+export function every<A>(predicate: Predicate<A>): Predicate<ReadonlyArray<A>> {
+  return (as) => as.every(predicate)
+}
 
 /**
  * Check if a predicate holds true for any array member.
diff --git a/src/ReadonlyRecord.ts b/src/ReadonlyRecord.ts
index 9394546d..8739739e 100644
--- a/src/ReadonlyRecord.ts
+++ b/src/ReadonlyRecord.ts
@@ -1093,7 +1093,11 @@ export function fromFoldableMap<F, B>(
  *
  * @since 2.5.0
  */
-export function every<A>(predicate: Predicate<A>): (r: ReadonlyRecord<string, A>) => boolean {
+export function every<A, B extends A>(
+  refinement: Refinement<A, B>
+): Refinement<ReadonlyRecord<string, A>, ReadonlyRecord<string, B>>
+export function every<A>(predicate: Predicate<A>): Predicate<ReadonlyRecord<string, A>>
+export function every<A>(predicate: Predicate<A>): Predicate<ReadonlyRecord<string, A>> {
   return (r) => {
     for (const k in r) {
       if (!predicate(r[k])) {
diff --git a/src/ReadonlySet.ts b/src/ReadonlySet.ts
index 256b4097..acb58cb8 100644
--- a/src/ReadonlySet.ts
+++ b/src/ReadonlySet.ts
@@ -468,7 +468,11 @@ export const some = <A>(predicate: Predicate<A>) => (set: ReadonlySet<A>): boole
 /**
  * @since 2.5.0
  */
-export const every = <A>(predicate: Predicate<A>): ((set: ReadonlySet<A>) => boolean) => not(some(not(predicate)))
+export function every<A, B extends A>(refinement: Refinement<A, B>): Refinement<ReadonlySet<A>, ReadonlySet<B>>
+export function every<A>(predicate: Predicate<A>): Predicate<ReadonlySet<A>>
+export function every<A>(predicate: Predicate<A>): Predicate<ReadonlySet<A>> {
+  return not(some(not(predicate)))
+}
 
 // TODO: remove non-curried overloading in v3
 /**
diff --git a/src/Record.ts b/src/Record.ts
index 94c3fb59..4be07adc 100644
--- a/src/Record.ts
+++ b/src/Record.ts
@@ -829,7 +829,10 @@ export function fromFoldableMap<F, B>(
  *
  * @since 2.0.0
  */
-export const every: <A>(predicate: Predicate<A>) => (r: Record<string, A>) => boolean = RR.every
+export const every: {
+  <A, B extends A>(refinement: Refinement<A, B>): Refinement<Record<string, A>, Record<string, B>>
+  <A>(predicate: Predicate<A>): Predicate<Record<string, A>>
+} = RR.every as any
 
 /**
  * Test if at least one value in a `Record` satisfies the predicate.
diff --git a/src/Set.ts b/src/Set.ts
index 9b5179f7..a3edcea0 100644
--- a/src/Set.ts
+++ b/src/Set.ts
@@ -455,7 +455,10 @@ export const some: <A>(predicate: Predicate<A>) => (set: Set<A>) => boolean = RS
 /**
  * @since 2.0.0
  */
-export const every: <A>(predicate: Predicate<A>) => (set: Set<A>) => boolean = RS.every
+export const every: {
+  <A, B extends A>(refinement: Refinement<A, B>): Refinement<Set<A>, Set<B>>
+  <A>(predicate: Predicate<A>): Predicate<Set<A>>
+} = RS.every as any
 
 /**
  * @since 2.10.0
diff --git a/src/TaskEither.ts b/src/TaskEither.ts
index 28c4608f..96a76d42 100644
--- a/src/TaskEither.ts
+++ b/src/TaskEither.ts
@@ -254,8 +254,6 @@ export const getOrElseW: <E, B>(
 /**
  * Transforms a `Promise` that may reject to a `Promise` that never rejects and returns an `Either` instead.
  *
- * Note: `f` should never `throw` errors, they are not caught.
- *
  * See also [`tryCatchK`](#trycatchk).
  *
  * @example
@@ -272,8 +270,16 @@ export const getOrElseW: <E, B>(
  * @category interop
  * @since 2.0.0
  */
-export const tryCatch = <E, A>(f: Lazy<Promise<A>>, onRejected: (reason: unknown) => E): TaskEither<E, A> => () =>
-  f().then(_.right, (reason) => _.left(onRejected(reason)))
+export const tryCatch = <E, A>(
+  f: Lazy<Promise<A>>,
+  onRejected: (reason: unknown) => E
+): TaskEither<E, A> => async () => {
+  try {
+    return await f().then(_.right)
+  } catch (reason) {
+    return _.left(onRejected(reason))
+  }
+}
 
 /**
  * Converts a function returning a `Promise` to one returning a `TaskEither`.
diff --git a/src/TaskOption.ts b/src/TaskOption.ts
index f38f7f30..6cf1dc1f 100644
--- a/src/TaskOption.ts
+++ b/src/TaskOption.ts
@@ -208,18 +208,18 @@ export const fromNullable: <A>(a: A) => TaskOption<NonNullable<A>> =
 /**
  * Transforms a `Promise` that may reject to a `Promise` that never rejects and returns an `Option` instead.
  *
- * Note: `f` should never `throw` errors, they are not caught.
- *
  * See also [`tryCatchK`](#trycatchk).
  *
  * @category interop
  * @since 2.10.0
  */
-export const tryCatch = <A>(f: Lazy<Promise<A>>): TaskOption<A> => () =>
-  f().then(
-    (a) => O.some(a),
-    () => O.none
-  )
+export const tryCatch = <A>(f: Lazy<Promise<A>>): TaskOption<A> => async () => {
+  try {
+    return await f().then(_.some)
+  } catch (reason) {
+    return _.none
+  }
+}
 
 /**
  * Converts a function returning a `Promise` to one returning a `TaskOption`.
diff --git a/src/pipeable.ts b/src/pipeable.ts
index 1cf4b05a..87f77c0a 100644
--- a/src/pipeable.ts
+++ b/src/pipeable.ts
@@ -1674,7 +1674,7 @@ export function pipeable<F, I>(I: { readonly URI: F } & I): Record<string, unkno
 }
 
 /**
- * Use [`pipe`](https://gcanti.github.io/fp-ts/modules/function.ts.html#flow) from `function` module instead.
+ * Use [`pipe`](https://gcanti.github.io/fp-ts/modules/function.ts.html#pipe) from `function` module instead.
  *
  * @since 2.0.0
  * @deprecated


Test patch:
diff --git a/test/TaskEither.ts b/test/TaskEither.ts
index afb97228..ed733116 100644
--- a/test/TaskEither.ts
+++ b/test/TaskEither.ts
@@ -452,16 +452,23 @@ describe('TaskEither', () => {
     U.deepStrictEqual(await pipe(_.right('a'), _.chainIOEitherK(f))(), E.right(1))
   })
 
-  it('tryCatchK', async () => {
-    const f = (n: number) => {
-      if (n > 0) {
-        return Promise.resolve(n * 2)
-      }
-      return Promise.reject('negative')
-    }
-    const g = _.tryCatchK(f, identity)
-    U.deepStrictEqual(await g(1)(), E.right(2))
-    U.deepStrictEqual(await g(-1)(), E.left('negative'))
+  describe('tryCatchK', () => {
+    test('with a resolved promise', async () => {
+      const g = _.tryCatchK((a: number) => Promise.resolve(a), identity)
+      U.deepStrictEqual(await g(1)(), E.right(1))
+    })
+
+    test('with a rejected promise', async () => {
+      const g = _.tryCatchK((a: number) => Promise.reject(a), identity)
+      U.deepStrictEqual(await g(-1)(), E.left(-1))
+    })
+
+    test('with a thrown error', async () => {
+      const g = _.tryCatchK((_: number) => {
+        throw new Error('Some error')
+      }, identity)
+      U.deepStrictEqual(await g(-1)(), E.left(new Error('Some error')))
+    })
   })
 
   // -------------------------------------------------------------------------------------
@@ -478,21 +485,23 @@ describe('TaskEither', () => {
     U.deepStrictEqual(await _.leftIO(I.of(1))(), E.left(1))
   })
 
-  it('tryCatch', async () => {
-    U.deepStrictEqual(
-      await _.tryCatch(
-        () => Promise.resolve(1),
-        () => 'error'
-      )(),
-      E.right(1)
-    )
-    U.deepStrictEqual(
-      await _.tryCatch(
-        () => Promise.reject(undefined),
-        () => 'error'
-      )(),
-      E.left('error')
-    )
+  describe('tryCatch', () => {
+    test('with a resolving promise', async () => {
+      U.deepStrictEqual(await _.tryCatch(() => Promise.resolve(1), identity)(), E.right(1))
+    })
+
+    test('with a rejected promise', async () => {
+      U.deepStrictEqual(await _.tryCatch(() => Promise.reject(1), identity)(), E.left(1))
+    })
+
+    test('with a thrown error', async () => {
+      U.deepStrictEqual(
+        await _.tryCatch(() => {
+          throw new Error('Some error')
+        }, identity)(),
+        E.left(new Error('Some error'))
+      )
+    })
   })
 
   it('fromIOEither', async () => {
diff --git a/test/TaskOption.ts b/test/TaskOption.ts
index 1f29c049..6a8f6d0a 100644
--- a/test/TaskOption.ts
+++ b/test/TaskOption.ts
@@ -89,9 +89,23 @@ describe('TaskOption', () => {
   // constructors
   // -------------------------------------------------------------------------------------
 
-  it('tryCatch', async () => {
-    U.deepStrictEqual(await _.tryCatch(() => Promise.resolve(1))(), O.some(1))
-    U.deepStrictEqual(await _.tryCatch(() => Promise.reject())(), O.none)
+  describe('tryCatch', () => {
+    test('with a resolving promise', async () => {
+      U.deepStrictEqual(await _.tryCatch(() => Promise.resolve(1))(), O.some(1))
+    })
+
+    test('with a rejected promise', async () => {
+      U.deepStrictEqual(await _.tryCatch(() => Promise.reject(1))(), O.none)
+    })
+
+    test('with a thrown error', async () => {
+      U.deepStrictEqual(
+        await _.tryCatch(() => {
+          throw new Error('Some error')
+        })(),
+        O.none
+      )
+    })
   })
 
   it('fromNullable', async () => {
@@ -288,11 +302,23 @@ describe('TaskOption', () => {
     })
   })
 
-  it('tryCatchK', async () => {
-    const f = (n: number) => (n > 0 ? Promise.resolve(n) : Promise.reject(n))
-    const g = _.tryCatchK(f)
-    U.deepStrictEqual(await g(1)(), O.some(1))
-    U.deepStrictEqual(await g(-1)(), O.none)
+  describe('tryCatchK', () => {
+    test('with a resolved promise', async () => {
+      const g = _.tryCatchK((a: number) => Promise.resolve(a))
+      U.deepStrictEqual(await g(1)(), O.some(1))
+    })
+
+    test('with a rejected promise', async () => {
+      const g = _.tryCatchK((a: number) => Promise.reject(a))
+      U.deepStrictEqual(await g(-1)(), O.none)
+    })
+
+    test('with a thrown error', async () => {
+      const g = _.tryCatchK((_: number) => {
+        throw new Error('Some error')
+      })
+      U.deepStrictEqual(await g(-1)(), O.none)
+    })
   })
 
   it('match', async () => {