Skip to content

Commit

Permalink
Ordering matchW added
Browse files Browse the repository at this point in the history
  • Loading branch information
mlegenhausen authored and gcanti committed Apr 21, 2022
1 parent ed90b56 commit ebc1e8a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
17 changes: 17 additions & 0 deletions docs/modules/Ordering.ts.md
Expand Up @@ -16,6 +16,7 @@ Added in v2.0.0
- [reverse](#reverse)
- [destructors](#destructors)
- [match](#match)
- [matchW](#matchw)
- [instances](#instances)
- [Eq](#eq)
- [Monoid](#monoid)
Expand Down Expand Up @@ -55,6 +56,22 @@ export declare const match: <A>(onLessThan: () => A, onEqual: () => A, onGreater

Added in v2.10.0

## matchW

Less strict version of [`match`](#match).

**Signature**

```ts
export declare const matchW: <A, B, C>(
onLessThan: () => A,
onEqual: () => B,
onGreaterThan: () => C
) => (o: Ordering) => A | B | C
```

Added in v2.11.0

# instances

## Eq
Expand Down
13 changes: 11 additions & 2 deletions src/Ordering.ts
Expand Up @@ -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 = <A, B, C>(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 = <A>(onLessThan: () => A, onEqual: () => A, onGreaterThan: () => A) => (o: Ordering): A =>
o === -1 ? onLessThan() : o === 0 ? onEqual() : onGreaterThan()
export const match: <A>(onLessThan: () => A, onEqual: () => A, onGreaterThan: () => A) => (o: Ordering) => A = matchW

// -------------------------------------------------------------------------------------
// combinators
Expand Down

0 comments on commit ebc1e8a

Please sign in to comment.