-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: strike and pattern to use overloads
As nice as using the rest arguments would be, I decided to switch strike and pattern to use explicit overloads for up to 10 match arms. this choice was made because strike & pattern need to TELL match what type TIn is, to prevent having to explicitly tell each match arm what type it's matching on this change also simplifies the signatures of strike and pattern. While there are a lot, it should hopefully be easier to unpack.
- Loading branch information
1 parent
c5e960c
commit 4e43728
Showing
18 changed files
with
513 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
/** | ||
* @description | ||
* A reference to a `new`-able constructor | ||
* | ||
* @internal | ||
*/ | ||
export interface Ctor<T> { | ||
new (...args: unknown[]): T; | ||
new (...args: any[]): T; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {DefaultExecutor} from './default-executor'; | ||
import {MatchExecutor} from './match-executor'; | ||
import {UnwrapExecutor} from './unwrap-executor'; | ||
|
||
export type AnyExecutor<TIn, TOut> = MatchExecutor<TIn, TOut> | DefaultExecutor<TIn, TOut> | UnwrapExecutor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
import {DefaultExecutor, MatchExecutor} from '../match-execution/types'; | ||
import {UnwrapExecutor} from '../match-execution/types/unwrap-executor'; | ||
|
||
/** | ||
* @description | ||
* Interface containing the function signatures for | ||
* pattern, without default cases. | ||
* | ||
* @internal | ||
*/ | ||
export interface PatternNonExhaustiveSigs { | ||
<TIn, TOut>(arm0: MatchExecutor<TIn, TOut>): (val: TIn) => TIn | TOut; | ||
<TIn, TOut>(arm0: MatchExecutor<TIn, TOut>, arm1: MatchExecutor<TIn, TOut>): (val: TIn) => TIn | TOut; | ||
<TIn, TOut>(arm0: MatchExecutor<TIn, TOut>, arm1: MatchExecutor<TIn, TOut>, arm2: MatchExecutor<TIn, TOut>): ( | ||
val: TIn | ||
) => TIn | TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
arm3: MatchExecutor<TIn, TOut> | ||
): (val: TIn) => TIn | TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
arm3: MatchExecutor<TIn, TOut>, | ||
arm4: MatchExecutor<TIn, TOut> | ||
): (val: TIn) => TIn | TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
arm3: MatchExecutor<TIn, TOut>, | ||
arm4: MatchExecutor<TIn, TOut>, | ||
arm5: MatchExecutor<TIn, TOut> | ||
): (val: TIn) => TIn | TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
arm3: MatchExecutor<TIn, TOut>, | ||
arm4: MatchExecutor<TIn, TOut>, | ||
arm5: MatchExecutor<TIn, TOut>, | ||
arm6: MatchExecutor<TIn, TOut> | ||
): (val: TIn) => TIn | TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
arm3: MatchExecutor<TIn, TOut>, | ||
arm4: MatchExecutor<TIn, TOut>, | ||
arm5: MatchExecutor<TIn, TOut>, | ||
arm6: MatchExecutor<TIn, TOut>, | ||
arm7: MatchExecutor<TIn, TOut> | ||
): (val: TIn) => TIn | TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
arm3: MatchExecutor<TIn, TOut>, | ||
arm4: MatchExecutor<TIn, TOut>, | ||
arm5: MatchExecutor<TIn, TOut>, | ||
arm6: MatchExecutor<TIn, TOut>, | ||
arm7: MatchExecutor<TIn, TOut>, | ||
arm8: MatchExecutor<TIn, TOut> | ||
): (val: TIn) => TIn | TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
arm3: MatchExecutor<TIn, TOut>, | ||
arm4: MatchExecutor<TIn, TOut>, | ||
arm5: MatchExecutor<TIn, TOut>, | ||
arm6: MatchExecutor<TIn, TOut>, | ||
arm7: MatchExecutor<TIn, TOut>, | ||
arm8: MatchExecutor<TIn, TOut>, | ||
arm9: MatchExecutor<TIn, TOut> | ||
): (val: TIn) => TIn | TOut; | ||
} | ||
|
||
/** | ||
* @description | ||
* Interface containing the function signatures for | ||
* strike, with default cases. | ||
* | ||
* @internal | ||
*/ | ||
export interface PatternExhaustiveSigs { | ||
<TIn, TOut>(arm0: MatchExecutor<TIn, TOut>, otherwise: DefaultExecutor<TIn> | UnwrapExecutor): (val: TIn) => TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
otherwise: DefaultExecutor<TIn> | UnwrapExecutor | ||
): (val: TIn) => TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
otherwise: DefaultExecutor<TIn> | UnwrapExecutor | ||
): (val: TIn) => TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
arm3: MatchExecutor<TIn, TOut>, | ||
otherwise: DefaultExecutor<TIn> | UnwrapExecutor | ||
): (val: TIn) => TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
arm3: MatchExecutor<TIn, TOut>, | ||
arm4: MatchExecutor<TIn, TOut>, | ||
otherwise: DefaultExecutor<TIn> | UnwrapExecutor | ||
): (val: TIn) => TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
arm3: MatchExecutor<TIn, TOut>, | ||
arm4: MatchExecutor<TIn, TOut>, | ||
arm5: MatchExecutor<TIn, TOut>, | ||
otherwise: DefaultExecutor<TIn> | UnwrapExecutor | ||
): (val: TIn) => TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
arm3: MatchExecutor<TIn, TOut>, | ||
arm4: MatchExecutor<TIn, TOut>, | ||
arm5: MatchExecutor<TIn, TOut>, | ||
arm6: MatchExecutor<TIn, TOut>, | ||
otherwise: DefaultExecutor<TIn> | UnwrapExecutor | ||
): (val: TIn) => TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
arm3: MatchExecutor<TIn, TOut>, | ||
arm4: MatchExecutor<TIn, TOut>, | ||
arm5: MatchExecutor<TIn, TOut>, | ||
arm6: MatchExecutor<TIn, TOut>, | ||
arm7: MatchExecutor<TIn, TOut>, | ||
otherwise: DefaultExecutor<TIn> | UnwrapExecutor | ||
): (val: TIn) => TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
arm3: MatchExecutor<TIn, TOut>, | ||
arm4: MatchExecutor<TIn, TOut>, | ||
arm5: MatchExecutor<TIn, TOut>, | ||
arm6: MatchExecutor<TIn, TOut>, | ||
arm7: MatchExecutor<TIn, TOut>, | ||
arm8: MatchExecutor<TIn, TOut>, | ||
otherwise: DefaultExecutor<TIn> | UnwrapExecutor | ||
): (val: TIn) => TOut; | ||
<TIn, TOut>( | ||
arm0: MatchExecutor<TIn, TOut>, | ||
arm1: MatchExecutor<TIn, TOut>, | ||
arm2: MatchExecutor<TIn, TOut>, | ||
arm3: MatchExecutor<TIn, TOut>, | ||
arm4: MatchExecutor<TIn, TOut>, | ||
arm5: MatchExecutor<TIn, TOut>, | ||
arm6: MatchExecutor<TIn, TOut>, | ||
arm7: MatchExecutor<TIn, TOut>, | ||
arm8: MatchExecutor<TIn, TOut>, | ||
arm9: MatchExecutor<TIn, TOut>, | ||
otherwise: DefaultExecutor<TIn> | UnwrapExecutor | ||
): (val: TIn) => TOut; | ||
} |
Oops, something went wrong.