Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Any side effect function in TaskEither or Either? #146

Closed
samuelyung opened this issue Feb 29, 2024 · 3 comments
Closed

[Question] Any side effect function in TaskEither or Either? #146

samuelyung opened this issue Feb 29, 2024 · 3 comments
Labels
question Asking about fpdart and functional programming

Comments

@samuelyung
Copy link

Hi, I come from Java (vavr) and for the side effect function I mean something like peek(), that is, just peek without changing Right if it's a Right, and for Left it is called peekLeft().

Now I need to do something like this to simulate peek:

taskEither.map((right) {
  doSomething(right);
  return right;
})
@SandroMaglione
Copy link
Owner

Hi @samuelyung

I think what you are looking for is chainFirst.

@SandroMaglione SandroMaglione added the question Asking about fpdart and functional programming label Mar 18, 2024
@samuelyung
Copy link
Author

No...

chainFirst() requires a function argument having a return type of TaskEither<L, C>, while the peek()'s Consumer argument doesn't return anything.
That is, it just "observe" the value.

@SandroMaglione
Copy link
Owner

You can return a TaskEither with return type as void. When chainFirst is executed the result is ignored, so in practice it works as if you are observing the value

@samuelyung samuelyung closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking about fpdart and functional programming
Projects
None yet
Development

No branches or pull requests

2 participants