Skip to content

Conversation

@LaureRC
Copy link
Contributor

@LaureRC LaureRC commented Mar 13, 2025

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Add Effect.traverseOption. Today in our codebase we're using a helper to do that, but I really think it would be a nice addition that would be useful to others.

I'm aware that we could use the Effect.transposeOption:

pipe(
  Effect.succeed(Option.some('value')), 
  Effect.map(Option.map(someEffectfulOperation)), 
  Effect.flatMap(Effect.transposeOption)
)

But this is simpler and more relevant for all the use cases where I need it in my work:

pipe(
  Effect.succeed(Option.some('value')),
  Effect.flatMap(Effect.traverseOption(someEffectfulOperation))
)

So I'd still push for this addition, hence my move to try to open a PR for it! :)

For the naming of this method, in our codebase we used optionTraverseEffect but given the discussions in issue #3142, it seems that adding this method in the Effect module and using the term traverse would be the way to go.
Also, if you agree with this addition and have ideas on improving the documentation part of this feature I'm interested as I'm not fully happy with my final version.

Related

@LaureRC LaureRC requested a review from mikearnaldi as a code owner March 13, 2025 12:12
@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog Mar 13, 2025
@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2025

🦋 Changeset detected

Latest commit: 31acdef

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

This PR includes changesets to release 36 packages
Name Type
effect Minor
@effect/cli Major
@effect/cluster-browser Major
@effect/cluster-node Major
@effect/cluster-workflow Major
@effect/cluster Major
@effect/experimental Major
@effect/opentelemetry Major
@effect/platform-browser Major
@effect/platform-bun Major
@effect/platform-node-shared Major
@effect/platform-node Major
@effect/platform Major
@effect/printer-ansi Major
@effect/printer Major
@effect/rpc-http Major
@effect/rpc Major
@effect/sql-clickhouse Major
@effect/sql-d1 Major
@effect/sql-drizzle Major
@effect/sql-kysely Major
@effect/sql-libsql Major
@effect/sql-mssql Major
@effect/sql-mysql2 Major
@effect/sql-pg Major
@effect/sql-sqlite-bun Major
@effect/sql-sqlite-do Major
@effect/sql-sqlite-node Major
@effect/sql-sqlite-react-native Major
@effect/sql-sqlite-wasm Major
@effect/sql Major
@effect/typeclass Major
@effect/vitest Major
@effect/ai Major
@effect/ai-anthropic Major
@effect/ai-openai Major

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

@gcanti
Copy link
Contributor

gcanti commented Mar 13, 2025

I would go with Effect.transposeMapOption as it follows the same pattern as filterMap: applying map first, then transpose, just like filterMap applies map first, then filter. Additionally, both APIs would appear when you start typing transpo....

@LaureRC
Copy link
Contributor Author

LaureRC commented Mar 13, 2025

I would go with Effect.transposeMapOption as it follows the same pattern as filterMap: applying map first, then transpose, just like filterMap applies map first, then filter. Additionally, both APIs would appear when you start typing transpo....

I completely agree with your points so I pushed a new commit to use that naming :)

And nice catch on the documentation example, sorry for that! It's now fixed!

@LaureRC LaureRC changed the title Add Effect.traverseOption Add Effect.transposeMapOption Mar 13, 2025
@gcanti gcanti merged commit dfe178b into Effect-TS:next-minor Mar 13, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from Discussion Ongoing to Done in PR Backlog Mar 13, 2025
@effect-bot effect-bot mentioned this pull request Mar 13, 2025
effect-bot pushed a commit that referenced this pull request Mar 13, 2025
effect-bot pushed a commit that referenced this pull request Mar 13, 2025
effect-bot pushed a commit that referenced this pull request Mar 13, 2025
effect-bot pushed a commit that referenced this pull request Mar 14, 2025
effect-bot pushed a commit that referenced this pull request Mar 15, 2025
effect-bot pushed a commit that referenced this pull request Mar 15, 2025
effect-bot pushed a commit that referenced this pull request Mar 16, 2025
effect-bot pushed a commit that referenced this pull request Mar 17, 2025
effect-bot pushed a commit that referenced this pull request Mar 17, 2025
tim-smart pushed a commit that referenced this pull request Mar 19, 2025
effect-bot pushed a commit that referenced this pull request Mar 19, 2025
effect-bot pushed a commit that referenced this pull request Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Add Option.mapEffect for better native interoperability between Option and Effect.

2 participants