# Building Tiny Effects (Learning Effect, Part 2)

- Published: 2026-07-11
- Updated: 2026-10-17
- Tags: Learning Effect, Effect, TypeScript
- URL: https://devtrillo.com/writing/learning-effect-2-building-tiny-effects/

The first Effect post gave me the shape:

```ts
Effect.Effect<Success, Error, Requirements>;
```

Now I want the smallest thing I can build with it.

No services. No architecture. No big theory.

Just success and failure.

## The plain version

In plain TypeScript, success and failure take different roads.

```ts
const getName = (input: string): string => {
  if (input === "") {
    throw new Error("Name is required");
  }

  return input;
};
```

Success comes back through `return`.

Failure leaves through `throw`.

Only one of them shows up in the type.

Effect gives both of them a value you can hold.

## A successful Effect

```ts
import { Effect } from "effect";

const answer = Effect.succeed(42);
```

The type is:

```ts
Effect.Effect<number, never, never>;
```

Read it slowly:

- success: `number`
- error: `never`
- requirements: `never`

This Effect gives you a number. It cannot fail. It needs nothing.

**Quiz:** What does Effect.succeed(42) put in the success slot?

- number
- Error
- never

**Answer:** number — The value inside succeed becomes the success type. Here, 42 is a number.

## A failed Effect

```ts
class MissingName {
  readonly _tag = "MissingName";
}

const failed = Effect.fail(new MissingName());
```

The type is:

```ts
Effect.Effect<never, MissingName, never>;
```

That looks weird at first.

But it makes sense. This Effect does not produce a success value. It only fails.

So the success slot is `never`.

**Quiz:** What does Effect.fail(new MissingName()) put in the error slot?

- MissingName
- never
- string

**Answer:** MissingName — The value passed to fail becomes the error type of the Effect.

## The pipe is just the path

Effect code often uses `.pipe(...)`.

```ts
const program = Effect.succeed("trillo").pipe(
  Effect.map((name) => name.toUpperCase()),
);
```

This reads as:

1. start with `"trillo"`
2. turn it into uppercase
3. return a new Effect

The program still has not run.

It is still a description.

**Quiz:** After mapping 'trillo' to uppercase, what is the success type?

- string
- number
- never

**Answer:** string — toUpperCase returns a string, so the success slot stays string.

## The mistake: throwing inside an Effect

Old habits come back fast.

```ts
const getName = (input: string) =>
  Effect.sync(() => {
    if (input === "") {
      throw new MissingName();
    }

    return input;
  });
```

This compiles.

The type is `Effect.Effect<string, never, never>`.

The error slot says `never`. The code can still fail.

Effect treats that throw as a defect. A defect is a crash you did not plan for. It never shows up in the error slot.

How to spot it: a `throw` inside `Effect.sync`, next to an error slot that says `never`.

Return the failure instead:

```ts
const getName = (input: string) =>
  input === "" ? Effect.fail(new MissingName()) : Effect.succeed(input);
```

Now the type is `Effect.Effect<string, MissingName, never>`.

The failure is back where you can see it.

## What I am taking with me

`succeed` and `fail` are not magic.

They are just the two smallest Effect values:

```ts
Effect.succeed(value);
Effect.fail(error);
```

One fills the success slot.

One fills the error slot.

> **Note:** If this feels too small, good. I want the boring pieces to feel boring before
> the bigger pieces show up
