Effect-TS / effect

An ecosystem of tools to build robust applications in TypeScript
https://effect.website
MIT License
7.51k stars 237 forks source link

DX improvement: Support `yield*` in even more places: Fibers, Deferreds, ... #3500

Open schickling opened 2 months ago

schickling commented 2 months ago

What is the problem this feature would solve?

Using the Effect generator syntax is really nice as some data types are "yieldable" however even more data types could be yieldable.

What is the feature you are proposing to solve the problem?

DX improvement: Support yield* in even more places: Fibers, Deferreds, ...

What alternatives have you considered?

No response

mikearnaldi commented 2 months ago

clarification: make Fiber, Ref, Deferred, etc subtypes of Effect

KhraksMamtsov commented 1 month ago
@mikearnaldi , What subtype should Fiber be? semantics
Fiber<A, E> Effect<A, E> Fiber.join
Fiber<A, E> Effect<Exit<A, E>> Fiber.await
// Fiber.join semantic
const value = yield* joinFiber
// Fiber.await
const exit = yield* awaitFiber 
const value = yield* exit

the first case can be expressed by the second one , but not vice versa

mikearnaldi commented 1 month ago

@mikearnaldi , What subtype should Fiber be?

semantics Fiber<A, E> Effect<A, E> Fiber.join Fiber<A, E> Effect<Exit<A, E>> Fiber.await

// Fiber.join semantic
const value = yield* joinFiber
// Fiber.await
const exit = yield* awaitFiber 
const value = yield* exit

the first case can be expressed by the second one , but not vice versa

they are semantically different, joining also merges fiber references while awaiting doesn't. I think along the lines of the rest I'd expect join to be the semantic of yielding

KhraksMamtsov commented 1 month ago

Are there any other entities that can be affected? Resource, Pool, PubSub? or is there no need for it yet?