esteban@devtrillo:~/blog/writing$
← cd -
$ cat learning-effect-4-map-vs-flatmap.md

Part 4: map vs flatMap

Jul 13, 2026·1 min read
$ tail -f learning-effect-4-map-vs-flatmap/readers
connecting…

I kept mixing up map and flatMap.

The rule is simple.

Use map when the callback returns a plain value.

Use flatMap when the callback returns an Effect.

That is it.

map changes the value

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

toUpperCase() returns a plain string.

So this is map.

Should this use map or flatMap? name => name.toUpperCase()

flatMap continues the program

const program = parseUserId("1").pipe(Effect.flatMap((id) => fetchUser(id)));

fetchUser(id) returns an Effect.

So this is flatMap.

Should this use map or flatMap? id => fetchUser(id)

The smell

If you use map with a function that returns an Effect, you get an Effect inside an Effect.

Effect.Effect<Effect.Effect<User, UserNotFound, never>, InvalidUserId, never>;

That type is trying to tell you something.

You probably wanted flatMap.

What usually caused Effect inside Effect?

What I am taking with me

The question is not “which operator do I like?”

The question is:

What does my callback return?

Plain value: map.

Effect value: flatMap.