# Fx.gen

Builds an Fx by yielding Effects and returning the Fx to run afterward.

## Signatures

```ts
export declare const gen: <Yield extends Effect.Effect<any, any, any>, Return extends Fx.Any>(f: () => Generator<Yield, Return, any>) => Fx<Fx.Success<Return>, Fx.Error<Return> | ([
    Yield
] extends [
    never
] ? never : Effect.Error<Yield>), Fx.Services<Return> | ([
    Yield
] extends [
    never
] ? never : Effect.Services<Yield>)>;
```

## Why

Setup logic often needs Effect services or failures before it can choose a
push producer. Generator notation keeps that dependency-aware setup linear
while preserving the returned Fx's success, error, and service channels.

## Ownership and lifetime

The generator is lazy: it runs for each subscription. Yielded Effects run
first; only their returned Fx is then subscribed. A setup failure prevents
the Fx from starting, and interruption cancels the active phase. Resources
acquired by yielded Effects must not escape unless managed independently;
use {@link genScoped } when setup and the returned Fx share a Scope.

## Examples

```ts
import { Effect } from "effect"
import { gen } from "@typed/fx/Fx"
import { succeed } from "@typed/fx/Fx"

const greeting = gen(function* () {
  const name = yield* Effect.succeed("Typed")
  return succeed(`Hello, ${name}`)
})
```
