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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Perform side effect and return original input (tee) #1039
Comments
example use case:
|
This seems to work for my use case:
usage:
Upload just returns a promise with an either (taskeither) error and void
The |
You may want import { pipe } from 'fp-ts/lib/pipeable'
import * as TE from 'fp-ts/lib/TaskEither'
declare const fileUrls: Array<string>
declare function upload(fileUrls: Array<string>): TE.TaskEither<Error, void>
declare function parseCsv(fileUrls: Array<string>): TE.TaskEither<Error, void>
pipe(TE.right(fileUrls), TE.chainFirst(upload), TE.chain(parseCsv)) |
@gcanti would be great to add this to the docs and a recipes/how to page... |
Yep, that worked - it's a direct replacement for my implementation. Thanks! |
@gkamperis any contribution to the documentation is welcomed! |
@gcanti of course... Is there an example I can look at? |
Just a quick question on this, what would be the correct way to implement this if you also didn't care if the upload failed or not? I'd like to be able to discard the Error state as well. Is there a better way to implement this? |
I think you can use |
you could define a const discard: <E>(ma: TE.TaskEither<E, void>) => TE.TaskEither<E, void> = TE.alt(() =>
TE.right(undefined as void)
)
const result = pipe(TE.right(fileUrls), TE.chainFirst(flow(upload, discard)), TE.chain(parseCsv)) in const result = pipe(TE.right(fileUrls), TE.chainFirstTaskK(upload), TE.chain(parseCsv)) |
馃摉 Documentation
Does fp-ts have a concept of a
tee
example: https://davefancher.com/2015/01/11/extending-f-pipelines-with-a-tee-function/鈥済iven a value, apply a function to it, ignore the result, then return the original value."
I've got a use case for
TaskEither
to perform some uploading and return the original input to the next pipeline function.The text was updated successfully, but these errors were encountered: