Skip to content

Commit

Permalink
feat: add ability to return an error in pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
gvergnaud committed Aug 29, 2024
1 parent 318759a commit 289a0d3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/internals/core/Core3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ namespace Tuple {
export type Last<xs> = xs extends [...any, infer last] ? last : never;
}

type ApplyLeftToRight<x extends any[], fns> = fns extends [
type ApplyLeftToRight<args extends any[], fns> = fns extends [
infer fn extends Fn,
...infer restFns
]
? ApplyLeftToRight<[Apply<fn, x>], restFns>
: x[0];
? Apply<fn, args> extends infer output
? output extends $.Error<any>
? output
: ApplyLeftToRight<[output], restFns>
: never
: args[0];

interface Piped<fns extends Fn[]> extends Fn {
name: "$.pipe";
Expand Down Expand Up @@ -151,6 +155,12 @@ namespace $ {
]
>
>;

const brand = Symbol.for("@hotscript/brand");

export interface Error<msg> {
[brand]: "@hotscript/error";
}
}

export type $<
Expand Down

0 comments on commit 289a0d3

Please sign in to comment.