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

[Question] How can I define an empty for each type of the ADT #187

Open
AlexandreRoba opened this issue Jun 18, 2023 · 1 comment
Open

Comments

@AlexandreRoba
Copy link

AlexandreRoba commented Jun 18, 2023

Hi,
First thanks for the library. It is very cool.
I have a question. Is there a way to loop on each element of the ADT and define an empty element?
I started with:

Object.keys(adt.keys).map((t)=>....)

But then I need to pattern match on a string/key, not on an element of the ADT. Any help appreciated.

@AlexandreRoba
Copy link
Author

I came up with something like:

export const emptyPersona = (type:(keyof typeof Persona.keys)):Persona=>{
  switch (type) {
    case 'personaFamilyComposition':
      return emptyPersonaFamilyComposition
    case 'personaPersonalSituation':
      return emptyPersonaPersonalSituation
    case 'personaSelfEmployed':
      return emptyPersonaSelfEmployed
  }
}

Not sure it is the best approach...

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