Skip to content

Latest commit

 

History

History
56 lines (43 loc) · 1.25 KB

test.md

File metadata and controls

56 lines (43 loc) · 1.25 KB

Utils.Task

Utility Task functions.

untilSuccess

untilSuccess : x -> List (Task x a) -> Task x a

Exectute a list of Tasks from left to right sequentially until one succeeds at which point processing of the list is terminated.

If all tasks fail then the failureValue is the result of the combined Task.

tasks : Task String Int
tasks =
    untilSuccess "None succeeded" [ Task.fail "nope", Task.succeed 1, Task.fail "never gets executed", Task.succeed 2 ]

andThenIf

andThenIf : Bool -> ( a -> Task x b, a -> Task x b ) -> Task x a -> Task x b

Conditional Task.andThen

This function helps reduces code clutter (by 2 lines).

with : Bool -> Task String ()
with flag =
    Task.succeed ()
        |> Task.andThen (\_ -> Task.succeed ())
        |> andThenIf flag
            ( \_ -> Task.succeed ()
            , always <| Task.fail "flag not set"
            )

without : Bool -> Task String ()
without flag =
    Task.succeed ()
        |> Task.andThen (\_ -> Task.succeed ())
        |> Task.andThen
            (flag
                ? ( \_ -> Task.succeed ()
                  , always <| Task.fail "flag not set"
                  )
            )