effect icon indicating copy to clipboard operation
effect copied to clipboard

Strict pattern matching

Open samhh opened this issue 8 months ago • 9 comments

What is the problem this feature would solve?

Walls of unneeded lambdas when pattern matching harm readability. For example:

import { Data } from "effect"

type Example = Data.TaggedEnum<{
  A: {},
  B: {},
  C: {},
  // etc
}>

const { $match } = Data.taggedEnum<Example>()

$match({
  A: () => "it is A",
  B: () => "this time it is B",
  C: () => "this is wild, it's C!",
  // etc
})

What is the feature you are proposing to solve the problem?

matchX simply makes each case strict. This has different performance characteristics, however in many cases it's viable and improves readability:

$matchX({
  A: "it is A",
  B: "this time it is B",
  C: "this is wild, it's C!",
  // etc
})

This is particularly relevant when there are potentially dozens of sum members.

What alternatives have you considered?

constant, tolerating the lambdas.

samhh avatar Jun 06 '24 16:06 samhh