From ebc1e8a18c208da032fb4e74693f1972445159fc Mon Sep 17 00:00:00 2001 From: mlegenhausen Date: Tue, 20 Jul 2021 08:55:31 +0200 Subject: [PATCH] Ordering matchW added --- docs/modules/Ordering.ts.md | 17 +++++++++++++++++ src/Ordering.ts | 13 +++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/docs/modules/Ordering.ts.md b/docs/modules/Ordering.ts.md index e8741de07..f89adb2bc 100644 --- a/docs/modules/Ordering.ts.md +++ b/docs/modules/Ordering.ts.md @@ -16,6 +16,7 @@ Added in v2.0.0 - [reverse](#reverse) - [destructors](#destructors) - [match](#match) + - [matchW](#matchw) - [instances](#instances) - [Eq](#eq) - [Monoid](#monoid) @@ -55,6 +56,22 @@ export declare const match: (onLessThan: () => A, onEqual: () => A, onGreater Added in v2.10.0 +## matchW + +Less strict version of [`match`](#match). + +**Signature** + +```ts +export declare const matchW: ( + onLessThan: () => A, + onEqual: () => B, + onGreaterThan: () => C +) => (o: Ordering) => A | B | C +``` + +Added in v2.11.0 + # instances ## Eq diff --git a/src/Ordering.ts b/src/Ordering.ts index 024541880..a36cc538b 100644 --- a/src/Ordering.ts +++ b/src/Ordering.ts @@ -19,12 +19,21 @@ export type Ordering = -1 | 0 | 1 // destructors // ------------------------------------------------------------------------------------- +/** + * Less strict version of [`match`](#match). + * + * @category destructors + * @since 2.11.0 + */ +export const matchW = (onLessThan: () => A, onEqual: () => B, onGreaterThan: () => C) => ( + o: Ordering +): A | B | C => (o === -1 ? onLessThan() : o === 0 ? onEqual() : onGreaterThan()) + /** * @category destructors * @since 2.10.0 */ -export const match = (onLessThan: () => A, onEqual: () => A, onGreaterThan: () => A) => (o: Ordering): A => - o === -1 ? onLessThan() : o === 0 ? onEqual() : onGreaterThan() +export const match: (onLessThan: () => A, onEqual: () => A, onGreaterThan: () => A) => (o: Ordering) => A = matchW // ------------------------------------------------------------------------------------- // combinators