Skip to content

Filter: add a way to map passing values, like mapFail does for failures #10696

Open

Description

@thewilkybarkid

What is the problem this feature would solve?

Filter has mapFail to transform a failing result, but nothing to transform a passing one. To filter and then transform a value, the transformation has to be written as a second filter that always succeeds, joined with compose:

Record.filterMap(
  Filter.compose(Filter.fromPredicate(Predicate.isNotUndefined), flow(toAttributeValue, Result.succeed)),
)

flow(f, Result.succeed) reads as a filter that can't fail, which hides that it's a plain mapping. In practice we fell back to a ternary inside Record.filterMap instead of using Filter.

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

A Filter.map (or mapPass, to mirror mapFail) that transforms the passing value and leaves failures unchanged:

Record.filterMap(
  pipe(Filter.fromPredicate(Predicate.isNotUndefined), Filter.map(toAttributeValue)),
)

Equivalent to compose(self, flow(f, Result.succeed)), with the same dual (data-first and data-last) signatures as mapFail.

What alternatives have you considered?

  • Filter.compose(self, flow(f, Result.succeed)), as above. It works but reads as an extra filter.
  • Filter.zipWith with a filter that always passes, which is more awkward still.
  • Writing the function by hand, e.g. value => (Predicate.isUndefined(value) ? Result.failVoid : Result.succeed(f(value))), which is what we did.

Tested with effect 4.1.2.

Activity

  1. added
    enhancement
    on Nov 17, 2026
  2. self-assigned this
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions