Effect CommunityEC
Effect Community2y ago
19 replies
jrovira

Understanding the Return Type of Effect/Option's `tap()` Function

Hello all,

I have a piece of code that looks like this:
if (Option.isSome(someOption)) { doWork(someOption.value) }

There Effect/Option package defines a tap() function which has basically the same functionality. My idea was to replace the previous code with the following:
Option.tap(someOption, someValue => doWork(someValue))

However, the f function parameter in tap() is defined as returning an Option (as can be seen here: https://github.com/Effect-TS/effect/blob/126133b106a52166bf21515a7bfa7779c1bdbbde/packages/effect/src/Option.ts#L787-L790).

My question is, why does the function parameter f: (a: A) => Option<_> have a return type? Shouldn't the return type be void?
Was this page helpful?