Effect CommunityEC
Effect Communityβ€’2y agoβ€’
35 replies
Stephen Bluck

Improving Reusability with Data.TaggedEnum

When using Data.TaggedEnum I find I am always exporting a match function and possibly an is function. I plan to make some helper in my project so I don't have to keep defining them:
export type Credential = Data.TaggedEnum<{
  Email: EmailPassword.Secure;
  Google: { email: S.EmailAddress };
  Apple: { email: S.EmailAddress };
}>;

export namespace Credential {
  export type Email = Data.TaggedEnum.Value<Credential, "Email">;
  export type Google = Data.TaggedEnum.Value<Credential, "Google">;
  export type Apple = Data.TaggedEnum.Value<Credential, "Apple">;

  export const { Apple, Email, Google } = Data.taggedEnum<Credential>();

  export const match = Match.typeTags<Credential>();
}

Something like this would be cool:
export const Credential = Data.taggedEnum<Credential>();

Credential.match({...})
Credential.is("Apple")

Thoughts?
Was this page helpful?