Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a ZIO-style Service type for idiomaticity points #661

Merged
merged 1 commit into from
Aug 20, 2020

Conversation

kitlangton
Copy link
Contributor

@kitlangton kitlangton commented Aug 19, 2020

There's usually (when adhering to the ZIO module pattern) a Service trait which defines interface (send and openWebsocket here).
In lieu of that refactoring, it could be nice to expose a Service type alias such that it could be idiomatically accessed when relying upon SttpClient in ones own ZLayers.

Then it would be trivial to refactor from

  def live(token: String): ZLayer[Console with SttpClient, Nothing, SlackClient] =
    ZLayer
      .fromServices[Console.Service, SttpBackend[Task, Stream[Throwable, Byte], WebSocketHandler], SlackClient.Service](
        (console: Console.Service, sttp: SttpBackend[Task, Stream[Throwable, Byte], WebSocketHandler]) =>
          LiveSlackClient(console, sttp, token)
      )

to

  def live(token: String): ZLayer[Console with SttpClient, Nothing, SlackClient] =
    ZLayer
      .fromServices[Console.Service, SttpClient.Service, SlackClient.Service](
        (console: Console.Service, sttp: SttpClient.Service) =>
          LiveSlackClient(console, sttp, token)
      )

Ahh, much better ;)

I'd also be happy to fully refactor this to use the trait Service pattern if that's something you'd be into, my dear sttp-eople.

Take care and thx for all the lovely software!

There's usually a `Service` trait nested within the objects which would define the interface (`send` and `openWebsocket` here).
In lieu of that refactoring, it could be nice to expose a `Service` type alias such that it could be easily used when relying on SttpClient in ones own ZLayers.

Then it would be trivial to refactor from 
```scala
  def live(token: String): ZLayer[Console with SttpClient, Nothing, SlackClient] =
    ZLayer
      .fromServices[Console.Service, SttpBackend[Task, Stream[Throwable, Byte], WebSocketHandler], SlackClient.Service](
        (console: Console.Service, sttp: SttpBackend[Task, Stream[Throwable, Byte], WebSocketHandler]) =>
          LiveSlackClient(console, sttp, token)
      )
```
to
```scala
  def live(token: String): ZLayer[Console with SttpClient, Nothing, SlackClient] =
    ZLayer
      .fromServices[Console.Service, SttpClient.Service, SlackClient.Service](
        (console: Console.Service, sttp: SttpClient.Service) =>
          LiveSlackClient(console, sttp, token)
      )
```

Ahh, much better ;)
@adamw adamw merged commit 31f54d5 into softwaremill:master Aug 20, 2020
@adamw
Copy link
Member

adamw commented Aug 20, 2020

Released in 2.2.5, thanks!

@kitlangton
Copy link
Contributor Author

Oh! Thank you @adamw :)

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.

2 participants