Tagless Final instead of hard-coded futures
See original GitHub issueI’ve been digging through the code a little and noticed that the direct use and execution of Futures brings some inconveniences with it:
- An
ExecutionContext
has to be passed everywhere. - You can’t use other libraries like Monix to perform the execution.
- You can’t reflect on the execution (e.g. in what sequence is stuff done).
- Tests always have to
await
.
I was wondering if you have considered / would consider a Final Tagless encoding instead of direct use of futures?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:17
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Can you give me a brief understanding on tagless final? : r/scala
Tagless Final, in essence, is about using traits instead of specific classes as your dependencies. Just as you might define traits for your...
Read more >Tagless final — from a different perspective | by Daniel Balazs
Without tagless final. In this case, the application uses cats IO as an effect type and that is hard-coded everywhere. Peter checks the...
Read more >Tagless final vs. akka-http routes - miklos.blog
Have you ever wondered how could you set up some akka-http routes for your tagless final program? Did you end up hardcoding your...
Read more >Introduction to Tagless final - Beyond the lines
Obviously the Id monad isn't stack-safe but Future or Task are. It's also possible to use a Trampoline instead of the Id monad...
Read more >The Tagless Final Pattern - Toby Hobson
The Tagless Final pattern allows us to abstract over the effect, for example allowing us wrap code in a Future or Id (no...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In fact, in most places you would not need to declare
F[_]
as an effect. So it might look like this:cats-effect
provides a number of type classes that describe the needed effect more granularly, e.g.Async
,Sync
,Concurrent
. But even then, a lot of code only needs to declareF[_]
to be something likeFunctor
(if you usemap
) orMonad
(if you useflatMap
), etc.Your point about how this looks to the user of the library is valid and something to consider. One approach could be to have the core library be parameterized on
F[_]
, which would be compatible with http4s and other parts of thecats-effect
ecosystem, and then provide a version of the types that are specialised toFuture
for backwards compatibility and easier use when integrating into, say, Play or Akka Http.I just stumbled upon another interesting use case, optimizing the execution: https://typelevel.org/blog/2017/12/27/optimizing-final-tagless.html The author @LukaJCB even mentions GraphQL as possible use case 😄