react-vite-demo

react and vite demo

git clone https://9o.is/git/react-vite-demo.git

pipe.ts

(6265B)


      1 /**
      2  * Pipes the value of an expression into a pipeline of functions.
      3  *
      4  * This is useful in combination with data-last functions as a simulation of methods:
      5  *
      6  * ```
      7  * as.map(f).filter(g) -> pipe(as, map(f), filter(g))
      8  * ```
      9  *
     10  * See also {@link flow}.
     11  *
     12  * @example
     13  * import { pipe } from "@fp-ts/core/Function"
     14  *
     15  * const length = (s: string): number => s.length
     16  * const double = (n: number): number => n * 2
     17  * const decrement = (n: number): number => n - 1
     18  *
     19  * assert.deepStrictEqual(pipe(length("hello"), double, decrement), 9)
     20  *
     21  * @since 1.0.0
     22  */
     23 export function pipe<A>(a: A): A
     24 export function pipe<A, B>(a: A, ab: (a: A) => B): B
     25 export function pipe<A, B, C>(a: A, ab: (a: A) => B, bc: (b: B) => C): C
     26 export function pipe<A, B, C, D>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): D
     27 export function pipe<A, B, C, D, E>(
     28   a: A,
     29   ab: (a: A) => B,
     30   bc: (b: B) => C,
     31   cd: (c: C) => D,
     32   de: (d: D) => E
     33 ): E
     34 export function pipe<A, B, C, D, E, F>(
     35   a: A,
     36   ab: (a: A) => B,
     37   bc: (b: B) => C,
     38   cd: (c: C) => D,
     39   de: (d: D) => E,
     40   ef: (e: E) => F
     41 ): F
     42 export function pipe<A, B, C, D, E, F, G>(
     43   a: A,
     44   ab: (a: A) => B,
     45   bc: (b: B) => C,
     46   cd: (c: C) => D,
     47   de: (d: D) => E,
     48   ef: (e: E) => F,
     49   fg: (f: F) => G
     50 ): G
     51 export function pipe<A, B, C, D, E, F, G, H>(
     52   a: A,
     53   ab: (a: A) => B,
     54   bc: (b: B) => C,
     55   cd: (c: C) => D,
     56   de: (d: D) => E,
     57   ef: (e: E) => F,
     58   fg: (f: F) => G,
     59   gh: (g: G) => H
     60 ): H
     61 export function pipe<A, B, C, D, E, F, G, H, I>(
     62   a: A,
     63   ab: (a: A) => B,
     64   bc: (b: B) => C,
     65   cd: (c: C) => D,
     66   de: (d: D) => E,
     67   ef: (e: E) => F,
     68   fg: (f: F) => G,
     69   gh: (g: G) => H,
     70   hi: (h: H) => I
     71 ): I
     72 export function pipe<A, B, C, D, E, F, G, H, I, J>(
     73   a: A,
     74   ab: (a: A) => B,
     75   bc: (b: B) => C,
     76   cd: (c: C) => D,
     77   de: (d: D) => E,
     78   ef: (e: E) => F,
     79   fg: (f: F) => G,
     80   gh: (g: G) => H,
     81   hi: (h: H) => I,
     82   ij: (i: I) => J
     83 ): J
     84 export function pipe<A, B, C, D, E, F, G, H, I, J, K>(
     85   a: A,
     86   ab: (a: A) => B,
     87   bc: (b: B) => C,
     88   cd: (c: C) => D,
     89   de: (d: D) => E,
     90   ef: (e: E) => F,
     91   fg: (f: F) => G,
     92   gh: (g: G) => H,
     93   hi: (h: H) => I,
     94   ij: (i: I) => J,
     95   jk: (j: J) => K
     96 ): K
     97 export function pipe<A, B, C, D, E, F, G, H, I, J, K, L>(
     98   a: A,
     99   ab: (a: A) => B,
    100   bc: (b: B) => C,
    101   cd: (c: C) => D,
    102   de: (d: D) => E,
    103   ef: (e: E) => F,
    104   fg: (f: F) => G,
    105   gh: (g: G) => H,
    106   hi: (h: H) => I,
    107   ij: (i: I) => J,
    108   jk: (j: J) => K,
    109   kl: (k: K) => L
    110 ): L
    111 export function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(
    112   a: A,
    113   ab: (a: A) => B,
    114   bc: (b: B) => C,
    115   cd: (c: C) => D,
    116   de: (d: D) => E,
    117   ef: (e: E) => F,
    118   fg: (f: F) => G,
    119   gh: (g: G) => H,
    120   hi: (h: H) => I,
    121   ij: (i: I) => J,
    122   jk: (j: J) => K,
    123   kl: (k: K) => L,
    124   lm: (l: L) => M
    125 ): M
    126 export function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(
    127   a: A,
    128   ab: (a: A) => B,
    129   bc: (b: B) => C,
    130   cd: (c: C) => D,
    131   de: (d: D) => E,
    132   ef: (e: E) => F,
    133   fg: (f: F) => G,
    134   gh: (g: G) => H,
    135   hi: (h: H) => I,
    136   ij: (i: I) => J,
    137   jk: (j: J) => K,
    138   kl: (k: K) => L,
    139   lm: (l: L) => M,
    140   mn: (m: M) => N
    141 ): N
    142 export function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(
    143   a: A,
    144   ab: (a: A) => B,
    145   bc: (b: B) => C,
    146   cd: (c: C) => D,
    147   de: (d: D) => E,
    148   ef: (e: E) => F,
    149   fg: (f: F) => G,
    150   gh: (g: G) => H,
    151   hi: (h: H) => I,
    152   ij: (i: I) => J,
    153   jk: (j: J) => K,
    154   kl: (k: K) => L,
    155   lm: (l: L) => M,
    156   mn: (m: M) => N,
    157   no: (n: N) => O
    158 ): O
    159 
    160 export function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(
    161   a: A,
    162   ab: (a: A) => B,
    163   bc: (b: B) => C,
    164   cd: (c: C) => D,
    165   de: (d: D) => E,
    166   ef: (e: E) => F,
    167   fg: (f: F) => G,
    168   gh: (g: G) => H,
    169   hi: (h: H) => I,
    170   ij: (i: I) => J,
    171   jk: (j: J) => K,
    172   kl: (k: K) => L,
    173   lm: (l: L) => M,
    174   mn: (m: M) => N,
    175   no: (n: N) => O,
    176   op: (o: O) => P
    177 ): P
    178 
    179 export function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(
    180   a: A,
    181   ab: (a: A) => B,
    182   bc: (b: B) => C,
    183   cd: (c: C) => D,
    184   de: (d: D) => E,
    185   ef: (e: E) => F,
    186   fg: (f: F) => G,
    187   gh: (g: G) => H,
    188   hi: (h: H) => I,
    189   ij: (i: I) => J,
    190   jk: (j: J) => K,
    191   kl: (k: K) => L,
    192   lm: (l: L) => M,
    193   mn: (m: M) => N,
    194   no: (n: N) => O,
    195   op: (o: O) => P,
    196   pq: (p: P) => Q
    197 ): Q
    198 
    199 export function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R>(
    200   a: A,
    201   ab: (a: A) => B,
    202   bc: (b: B) => C,
    203   cd: (c: C) => D,
    204   de: (d: D) => E,
    205   ef: (e: E) => F,
    206   fg: (f: F) => G,
    207   gh: (g: G) => H,
    208   hi: (h: H) => I,
    209   ij: (i: I) => J,
    210   jk: (j: J) => K,
    211   kl: (k: K) => L,
    212   lm: (l: L) => M,
    213   mn: (m: M) => N,
    214   no: (n: N) => O,
    215   op: (o: O) => P,
    216   pq: (p: P) => Q,
    217   qr: (q: Q) => R
    218 ): R
    219 
    220 export function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S>(
    221   a: A,
    222   ab: (a: A) => B,
    223   bc: (b: B) => C,
    224   cd: (c: C) => D,
    225   de: (d: D) => E,
    226   ef: (e: E) => F,
    227   fg: (f: F) => G,
    228   gh: (g: G) => H,
    229   hi: (h: H) => I,
    230   ij: (i: I) => J,
    231   jk: (j: J) => K,
    232   kl: (k: K) => L,
    233   lm: (l: L) => M,
    234   mn: (m: M) => N,
    235   no: (n: N) => O,
    236   op: (o: O) => P,
    237   pq: (p: P) => Q,
    238   qr: (q: Q) => R,
    239   rs: (r: R) => S
    240 ): S
    241 
    242 export function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T>(
    243   a: A,
    244   ab: (a: A) => B,
    245   bc: (b: B) => C,
    246   cd: (c: C) => D,
    247   de: (d: D) => E,
    248   ef: (e: E) => F,
    249   fg: (f: F) => G,
    250   gh: (g: G) => H,
    251   hi: (h: H) => I,
    252   ij: (i: I) => J,
    253   jk: (j: J) => K,
    254   kl: (k: K) => L,
    255   lm: (l: L) => M,
    256   mn: (m: M) => N,
    257   no: (n: N) => O,
    258   op: (o: O) => P,
    259   pq: (p: P) => Q,
    260   qr: (q: Q) => R,
    261   rs: (r: R) => S,
    262   st: (s: S) => T
    263 ): T
    264 export function pipe(
    265   a: unknown,
    266   ab?: Function,
    267   bc?: Function,
    268   cd?: Function,
    269   de?: Function,
    270   ef?: Function,
    271   fg?: Function,
    272   gh?: Function,
    273   hi?: Function
    274 ): unknown {
    275   switch (arguments.length) {
    276     case 1:
    277       return a
    278     case 2:
    279       return ab!(a)
    280     case 3:
    281       return bc!(ab!(a))
    282     case 4:
    283       return cd!(bc!(ab!(a)))
    284     case 5:
    285       return de!(cd!(bc!(ab!(a))))
    286     case 6:
    287       return ef!(de!(cd!(bc!(ab!(a)))))
    288     case 7:
    289       return fg!(ef!(de!(cd!(bc!(ab!(a))))))
    290     case 8:
    291       return gh!(fg!(ef!(de!(cd!(bc!(ab!(a)))))))
    292     case 9:
    293       return hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a))))))))
    294     default: {
    295       let ret = arguments[0]
    296       for (let i = 1; i < arguments.length; i++) {
    297         ret = arguments[i](ret)
    298       }
    299       return ret
    300     }
    301   }
    302 }