Skip to content

Simplify FeatureFlagRegistry control flow#115

Closed
EtaCassiopeia wants to merge 1 commit into
mainfrom
refactor/feature-flag-registry-simplify
Closed

Simplify FeatureFlagRegistry control flow#115
EtaCassiopeia wants to merge 1 commit into
mainfrom
refactor/feature-flag-registry-simplify

Conversation

@EtaCassiopeia
Copy link
Copy Markdown
Owner

Summary

Two small simplifications in FeatureFlagRegistryLive:

  1. getClient — fuse .map(...).flatMap(...)

    ZIO#map(f) is implemented as flatMap(a => Exit.succeed(f(a))), so clients.get.map(_.get(domain)).flatMap(...) constructs two FlatMap nodes. Inlining the map into the flatMap callback reduces it to one:

    // Before
    clients.get.map(_.get(domain)).flatMap {
      case Some(c) => ZIO.succeed(c)
      case None    => createDomainClient(domain)
    }
    // After
    clients.get.flatMap(_.get(domain) match {
      case Some(c) => ZIO.succeed(c)
      case None    => createDomainClient(domain)
    })
  2. setProvider — collapse two-step for-comprehension

    The for-comprehension introduced an existing binding that was used exactly once. Inlining produces the same effect with less indirection.

Pure refactor; no behavior change.

Credit

Spotted in #110 by @guizmaii.

Test plan

  • All tests pass (340 + 99 + 170)
  • scalafmtCheckAll clean

@EtaCassiopeia
Copy link
Copy Markdown
Owner Author

Tested independently; closing in favor of #110.

@EtaCassiopeia EtaCassiopeia deleted the refactor/feature-flag-registry-simplify branch May 13, 2026 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant