website icon indicating copy to clipboard operation
website copied to clipboard

From Discord: Possible Docs example on using external libraries with Effect

Open effect-bot opened this issue 2 years ago • 0 comments

Summary

In the above conversation, we discussed the problem of creating an Effect from a Promise<Either<E, D>>. Initially, there was a suggestion to use Effect.promiseEither or Effect.runPromiseExit to achieve this. However, it was pointed out that it might be better to create a wrapper or utility function to handle the client and convert the result into an Effect directly.

The suggested approach was to create a wrapper function that encapsulates the Supabase client creation and query execution. This wrapper function would return an object with methods for executing queries. By using this wrapper function, you can directly return an Effect without having to manually convert the Promise<Either<E, D>> result.

The key takeaways from this conversation are:

  1. Encapsulate complexity in a single place by creating a wrapper function or utility to handle external APIs or services.
  2. Use the wrapper function to directly return an Effect instead of manually converting the Promise<Either<E, D>> result.
  3. By encapsulating complexity, you can easily mock the external API or service for testing purposes.
  4. Avoid the XY problem by focusing on solving the original issue rather than looking for a specific method or solution.

Discord thread

https://discord.com/channels/795981131316985866/1194569368445665340

effect-bot avatar Jan 10 '24 15:01 effect-bot