Stream: ideas

Topic: Task and Result onErr


view this post on Zulip Luke Boswell (Jun 23 2023 at 01:00):

I've found it confusing sometimes when working with Task and Result with the names of onErr verse onFail. I wonder if we could unify these to the same name? Should Task.onFail be renamed to Task.onErr?

This is their current type signatures:

Result.onErr : Result a err, (err -> Result a otherErr) -> Result a otherErr
Task.onFail : Task ok a, (a -> Task ok b) -> Task ok b

Note that both Result ok err and Task ok err are defined using err

view this post on Zulip Richard Feldman (Jun 23 2023 at 01:00):

I've been wondering the same thing...if we did that, should we rename Task.succeed to Task.ok?

view this post on Zulip Richard Feldman (Jun 23 2023 at 01:00):

so both of them would have ok and err

view this post on Zulip Luke Boswell (Jun 23 2023 at 01:01):

I'll write an example to see how it looks

view this post on Zulip Luke Boswell (Jun 23 2023 at 01:03):

Command.new "ls"
|> Command.arg "-al"
|> Command.arg dir
|> Command.output
|> Task.attempt \output ->
    when output.status is
        Ok {} ->
            output.stdout
            |> Str.split "\n"
            |> Task.ok
        Err (ExitCode code) ->
            codeStr = Num.toStr code
            Task.err "ls failed with exit code \(codeStr)"
        Err KilledBySignal ->
            Task.err "ls was killed by signal"
        Err (IOError err) ->
            Task.err "ls failed with IOError \(err)"

view this post on Zulip Luke Boswell (Jun 23 2023 at 01:03):

So we would have to also change Task.fail to Task.err too I assume

view this post on Zulip Richard Feldman (Jun 23 2023 at 01:06):

yeah I think so

view this post on Zulip Richard Feldman (Jun 23 2023 at 01:06):

looks fine to me!

view this post on Zulip Richard Feldman (Jun 23 2023 at 01:06):

curious what others think

view this post on Zulip Brendan Hansknecht (Jun 23 2023 at 01:11):

Task.ok looks weird to be, but I'll get used to it and I think unifying the api with Result will be nice.

view this post on Zulip Luke Boswell (Jun 23 2023 at 03:19):

Submitted PR #64 with this change.


Last updated: Jun 16 2026 at 16:19 UTC