Skip to content

Add Match.whenFilter for Filter-backed extracting cases - #10094

Merged
tim-smart merged 9 commits into
v4/next-minorfrom
agent/effect-bot/9cd942c7668c
Oct 29, 2026
Merged

tim-smart merged 9 commits into
v4/next-minorfrom
agent/effect-bot/9cd942c7668c

Conversation

@effect-bot

@effect-bot effect-bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds Match.whenFilter, an extracting case backed by the synchronous Filter<Input, Pass, Fail> contract.

const describeQuery = Match.type<string>().pipe(
  Match.when("", () => "empty"),
  Match.whenFilter(Filter.fromPredicateOption(queryToDomainLabel), (label) => `search:${label}`),
  Match.orElse(() => "invalid")
)
  • The filter runs once when the case is reached, and never after an earlier case matched.
  • On success the handler receives the filter's Pass value; on failure the Fail payload is discarded and matching continues with the original input.
  • Works with Match.value, Match.type and Match.fn (extra handler arguments), and respects Match.withReturnType.
  • Remaining-input bookkeeping is unchanged, so a whenFilter case never makes Match.exhaustive valid on its own.
  • Match.when is unchanged.

Match.Case is unchanged: whenFilter produces an ordinary When case. Its guard runs the filter and caches a successful result for the evaluate call that follows; evaluate consumes that cache (only for the same input) and re-runs the filter otherwise, so the filter runs once per match without stale reuse. The filter's input type is separate from the matcher's remaining input (R extends Input), so a broader filter does not widen the fallback input.

Validation

  • pnpm test --run packages/effect/test/Match.test.ts
  • pnpm test-types typetest/Match.tst.ts
  • pnpm check (packages/effect)
  • pnpm jsdocs --check
  • oxlint and dprint on the changed files
  • pnpm doctest --run packages/effect/src/Match.ts --testTimeout 90000 (58/58; the default 10s timeout is too short for cold startup on this machine)

Closes #9949
Closes EFF-2942

@changeset-bot

changeset-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e71ce3c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
effect Minor
@effect/opentelemetry Minor
@effect/vitest Minor
@effect/ai-anthropic Minor
@effect/ai-cloudflare Minor
@effect/ai-openai-compat Minor
@effect/ai-openai Minor
@effect/ai-openrouter Minor
@effect/ai-typesafe Minor
@effect/atom-react Minor
@effect/atom-solid Minor
@effect/atom-vue Minor
@effect/platform-browser Minor
@effect/platform-bun Minor
@effect/platform-deno Minor
@effect/platform-node-shared Minor
@effect/platform-node Minor
@effect/sql-clickhouse Minor
@effect/sql-d1 Minor
@effect/sql-libsql Minor
@effect/sql-mssql Minor
@effect/sql-mysql2 Minor
@effect/sql-pg Minor
@effect/sql-pglite Minor
@effect/sql-sqlite-bun Minor
@effect/sql-sqlite-do Minor
@effect/sql-sqlite-node Minor
@effect/sql-sqlite-react-native Minor
@effect/sql-sqlite-wasm Minor
@effect/docgen Minor
@effect/doctest Minor
@effect/graphql-generator Minor
@effect/openapi-generator Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-bot
effect-bot changed the base branch from main to v4/next-minor October 29, 2026 02:34
@effect-janitor effect-janitor Bot added the 4.0 label Oct 29, 2026
@effect-bot
effect-bot force-pushed the agent/effect-bot/9cd942c7668c branch from 70df6ef to 918ac80 Compare October 29, 2026 02:34
@effect-janitor effect-janitor Bot removed the 4.0 label Oct 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.35 KB 39.35 KB 0.00 KB (0.00%)
basic.ts 7.18 KB 7.18 KB 0.00 KB (0.00%)
batching.ts 11.06 KB 11.06 KB 0.00 KB (0.00%)
brand.ts 6.84 KB 6.84 KB 0.00 KB (0.00%)
cache.ts 11.49 KB 11.49 KB 0.00 KB (0.00%)
config.ts 22.77 KB 22.77 KB 0.00 KB (0.00%)
differ.ts 21.92 KB 21.92 KB 0.00 KB (0.00%)
http-client.ts 26.86 KB 26.86 KB 0.00 KB (0.00%)
http-router.ts 36.85 KB 36.85 KB 0.00 KB (0.00%)
logger.ts 11.96 KB 11.96 KB 0.00 KB (0.00%)
metric.ts 9.42 KB 9.42 KB 0.00 KB (0.00%)
optic.ts 7.05 KB 7.05 KB 0.00 KB (0.00%)
pubsub.ts 15.97 KB 15.97 KB 0.00 KB (0.00%)
queue.ts 12.77 KB 12.77 KB 0.00 KB (0.00%)
schedule.ts 11.74 KB 11.74 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.02 KB 14.02 KB 0.00 KB (0.00%)
schema-binary.ts 41.06 KB 41.06 KB 0.00 KB (0.00%)
schema-class.ts 21.65 KB 21.65 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.51 KB 29.51 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.91 KB 27.91 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.27 KB 15.27 KB 0.00 KB (0.00%)
schema-string.ts 12.26 KB 12.26 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.19 KB 16.19 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.87 KB 38.87 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 26.10 KB 26.10 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.83 KB 20.83 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 20.97 KB 20.97 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.07 KB 21.07 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.11 KB 26.11 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.16 KB 21.16 KB 0.00 KB (0.00%)
schema.ts 20.75 KB 20.75 KB 0.00 KB (0.00%)
stm.ts 14.15 KB 14.15 KB 0.00 KB (0.00%)
stream.ts 10.33 KB 10.33 KB 0.00 KB (0.00%)

@effect-bot
effect-bot force-pushed the agent/effect-bot/9cd942c7668c branch 2 times, most recently from 5eb5fdc to fe45a29 Compare October 29, 2026 03:07
@effect-bot
effect-bot force-pushed the agent/effect-bot/9cd942c7668c branch from fe45a29 to 5640573 Compare October 29, 2026 03:10
@effect-bot
effect-bot force-pushed the agent/effect-bot/9cd942c7668c branch from 5640573 to 7ff326d Compare October 29, 2026 03:15
@effect-bot
effect-bot force-pushed the agent/effect-bot/9cd942c7668c branch from 7ff326d to 766c98a Compare October 29, 2026 03:16
Base automatically changed from v4/next-minor to main October 29, 2026 03:31
@effect-janitor effect-janitor Bot added the 4.0 label Oct 29, 2026
@effect-bot
effect-bot changed the base branch from main to v4/next-minor October 29, 2026 03:34
@effect-janitor effect-janitor Bot removed the 4.0 label Oct 29, 2026
@effect-bot
effect-bot force-pushed the agent/effect-bot/9cd942c7668c branch from 1a16c43 to 64f0253 Compare October 29, 2026 03:42
@effect-bot
effect-bot force-pushed the agent/effect-bot/9cd942c7668c branch from 2536246 to e71ce3c Compare October 29, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Match: add extracting branches backed by Filter

2 participants