Implementing Immutable Map of Union Types in Effect

πŸ‘‹

I am trying to create an immutable map of immutable records that are disjunct unions. I think Effect supports that, but I cannot figure out what's the intended way of doing it.

// TypeScript Version
type _TypeA = {
  kind: "a";
  a: number;
};

type _TypeB = {
  kind: "b";
  b: string;
};

const ts = new Map<number, _TypeA | _TypeB>();

{
  const e = ts.get(1)!;

  switch (e.kind) {
    case "a":
      alert(e.a);
      break;
    case "b":
      alert(e.b);
      break;
  }
}


How could I achieve this with Effect? Do you recommend I check out @effect/schema or use the core library? How do I create immutable records/structs for _TypeA and _TypeB in Effect?

NOTE: I am not trying to parse or stringify data at this moment and I got confused whether @effect/schema is the right tool.
Was this page helpful?