11import { TNonFunction , TPredicateFunction } from "./TPredicateFunction" ;
22import { ISwitch } from "./ISwitch" ;
3-
4- export type Unpack < T > = T extends ( infer U ) [ ] ? U : T ;
3+ import { Unpack } from "./Unpack" ;
54
65class SwitchMatched < T , K > implements ISwitch < T , K > {
76 public static for < T > ( x : T ) : any {
@@ -20,18 +19,18 @@ class SwitchMatched<T, K> implements ISwitch<T, K> {
2019}
2120
2221/**
23- * Switch resembles imperative switch statement using functions .
22+ * Switch resembles imperative switch statement using chaining .
2423 *
2524 * Internally, Switch behaves like Either in the sense that it preserves the position of Right
2625 * until it successfully matches case predicate (either function or value). If matching happens,
2726 * Switch becomes a kind of Left and holds the value until it reaches the .default call. If
2827 * matching didn't happen for all cases, the value of the .default argument is returned instead.
2928 */
30- export class Switch < T , K extends any [ ] > implements ISwitch < T , K > {
29+ export class Switch < T , K extends [ ] > implements ISwitch < T , K > {
3130 /**
3231 * Pointer interface for lifting a value into Switch.
3332 */
34- public static for < T , K extends any [ ] = [ ] > ( x : T ) : ISwitch < T , K > {
33+ public static for < T , K extends [ ] = [ ] > ( x : T ) : ISwitch < T , K > {
3534 return new Switch < T , K > ( x ) ;
3635 }
3736
@@ -49,11 +48,11 @@ export class Switch<T, K extends any[]> implements ISwitch<T, K> {
4948 * Define predicate function to be executed against Switch state and the value to be
5049 * returned in case of matching.
5150 */
52- public case < N > ( pred : TPredicateFunction < T > , res : N ) : ISwitch < T , [ Unpack < K > , N ] > ;
53- public case < N > ( pred : any , res : N ) : ISwitch < T , [ Unpack < K > , N ] > {
51+ public case < N > ( pred : TPredicateFunction < T > , value : N ) : ISwitch < T , [ Unpack < K > , N ] > ;
52+ public case < N > ( pred : any , value : N ) : ISwitch < T , [ Unpack < K > , N ] > {
5453 const check = typeof pred == "function" ? pred ( this . x ) : pred === this . x ;
5554
56- return check ? SwitchMatched . for ( res ) : Switch . for ( this . x ) ;
55+ return check ? SwitchMatched . for ( value ) : Switch . for ( this . x ) ;
5756 }
5857
5958 /**
0 commit comments