Testable.Task is a replacement for the core Task module. You can use it
to create components that can be tested with Testable.TestContext. You can
convert Testable.Task into a core Task with the Testable module.
A task that succeeds immediately when run.
succeed 42 -- results in 42A task that fails immediately when run.
fail "file not found" : Task String aTransform a task.
map sqrt (succeed 9) == succeed 3Chain together a task and a callback. The first task will run, and if it is successful, you give the result to the callback resulting in another task. This task then gets run.
succeed 2 |> andThen (\n -> succeed (n + 2)) == succeed 4This is useful for chaining tasks together. Maybe you need to get a user from your servers and then lookup their picture once you know their name.
Helps with handling failure. Instead of having a task fail with some value
of type x it promotes the failure to a Nothing and turns all successes into
Just something.
toMaybe (fail "file not found") == succeed Nothing
toMaybe (succeed 42) == succeed (Just 42)This means you can handle the error with the Maybe module instead.
Helps with handling failure. Instead of having a task fail with some value
of type x it promotes the failure to an Err and turns all successes into
Ok something.
toResult (fail "file not found") == succeed (Err "file not found")
toResult (succeed 42) == succeed (Ok 42)This means you can handle the error with the Result module instead.
Make a thread sleep for a certain amount of time. The following example sleeps for 1 second and then succeeds with 42.
sleep 1000 |> andThen \_ -> succeed 42
Represents asynchronous effects that may fail. It is useful for stuff like HTTP. For example, maybe we have a task with the type (
Task String User). This means that when we perform the task, it will either fail with aStringmessage or succeed with aUser. So this could represent a task that is asking a server for a certain user.