Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stricter handle function #10

Open
ENvironmentSet opened this issue Aug 24, 2023 · 0 comments
Open

Stricter handle function #10

ENvironmentSet opened this issue Aug 24, 2023 · 0 comments

Comments

@ENvironmentSet
Copy link
Owner

ENvironmentSet commented Aug 24, 2023

Currently, there's nothing at compile time preventing users from not calling handle tactics. I think we can add more restriction by forcing users to return special values which only produced by handle tactics. But I'm also concerning that this would make writing handlers little more complicated. Any thoughts?

type TacticIsCalled = unique symbol // some special type

interface HandleTactics<in ER, in R> {
  resume(value: ER): TacticIsCalled
  abort(value: R): TacticIsCalled
}

type Handlers<E extends Effects, R = never>
  = Simplify<
      UnionToIntersection<
        E extends Code<`${infer S}.${infer C}`, infer P, infer ER> ?
          Eq<P, never> extends false ?
            { [K in S]: { [K in C]: (...parameters: [...P, HandleTactics<ER, R>]) => TacticIsCalled | Generator<Effects, TacticIsCalled > } }
            : { [K in S]: { [K in C]: ER | Generator<Effects, ER> } }
          : never
      >
    >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant