Skip to content

Conversation

diesalbla
Copy link
Contributor

@diesalbla diesalbla commented May 28, 2022

In this code, the use of Alternative[Option] can be replaced with an if-then-else statement. Furthermore, we can replace the for-comprehension with a simple flatMap and less inlining.

Note: most changes are whitespace.

@mergify mergify bot added series/0.23 PRs targeting 0.23.x module:ember-core labels May 28, 2022
@@ -361,26 +361,21 @@ private[ember] object H2Client {
} yield (http1Client: TinyClient[F]) => { (req: Request[F]) =>
val key = H2Client.RequestKey.fromRequest(req)
val priorKnowledge = req.attributes.lookup(H2Keys.Http2PriorKnowledge).isDefined
val h2Prior = Alternative[Option].guard(priorKnowledge).as(Http2)
for {
socketType <- Resource.eval(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa, it seems socketType has been computing regardless of the guard's result. This refactoring could also bring saving a few processor ticks. 👏🏻

In this code, the use of Alternative[Option] can be replaced
with an if-then-else statement. Furthermore, we can replace
the for-comprehension with a simple flatMap and less inlining.
@diesalbla diesalbla force-pushed the embercore_h2client_no_alternative branch from 0d9fa5d to 5e5357f Compare May 28, 2022 18:21
).handleErrorWith[org.http4s.Response[F], Throwable] {
case InvalidSocketType() | MissingHost() | MissingPort() =>
Resource.eval(socketMap.update(s => s + (key -> Http1))) >>
http1Client(req)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@armanbilge Thanks for fixing this, just pushed a full change.

@armanbilge armanbilge merged commit 90f0b08 into http4s:series/0.23 May 28, 2022
@diesalbla diesalbla deleted the embercore_h2client_no_alternative branch May 28, 2022 19:29
@rossabaker rossabaker added the behind-the-scenes Appreciated, but not user-facing label Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
behind-the-scenes Appreciated, but not user-facing module:ember-core series/0.23 PRs targeting 0.23.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants