-
Notifications
You must be signed in to change notification settings - Fork 359
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
Task.andAlwaysThen proposal #1111
Comments
Thanks for reporting this! To set expectations:
Finally, please be patient with the core team. They are trying their best with limited resources. |
use andThen then onError |
show me how |
andThenWithResult : (Result x a -> Task x a) -> Task x a -> Task x a
andThenWithResult next task =
task
|> Task.andThen (\a -> next (Ok a))
|> Task.onError (\x -> next (Err x)) or with function composition, andThenWithResult : (Result x a -> Task x a) -> Task x a -> Task x a
andThenWithResult next =
Task.andThen (Ok >> next)
>> Task.onError (Err >> next) |
@avh4 I think that there is following problem:
|
edit: actually you are correct, i didn't pay attention to "nextTask fails" |
ah yeah, I think you're right @pravdomil I think this could be solved still somehow using andThen/onError, but you'd also wrap the error in another Result so you could tell the difference between the original task failing and |
Thanks for feedback |
I think this will do what you are asking for: toResult : Task x a -> Task y (Result x a)
toResult task =
Task.map Ok task
|> Task.onError (Task.succeed << Err)
andThenWithResult : (Result x a -> Task x a) -> Task x a -> Task x a
andThenWithResult next task =
toResult task
|> Task.andThen next |
@albertdahlin I think that works. I endup using: andAlwaysThen : (Result x a -> Task y b) -> Task x a -> Task y b
andAlwaysThen toTask a =
a
|> Task.map Ok
|> Task.onError (Err >> Task.succeed)
|> Task.andThen toTask |
Hello, I found no way how to do:
Someting like:
Any ideas?
EDIT: Also I'm searching for
andThenAlways
that will do a task regardless if the task failed or not.The text was updated successfully, but these errors were encountered: