Skip to content
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

Use ?? for Providing Defaults for Results #7089

Open
Tracked by #7086
smores56 opened this issue Sep 18, 2024 · 0 comments
Open
Tracked by #7086

Use ?? for Providing Defaults for Results #7089

smores56 opened this issue Sep 18, 2024 · 0 comments

Comments

@smores56
Copy link
Collaborator

We want to add a new operator ?? that acts as a Result.withDefault equivalent. Some example usages:

configFile = args.configFile ?? "~/.config/service.json"

dataItems =
    Config.readFile! configFile
   |> Result.try Json.decode
    ?? ["abc", "def", "ghi"]

It should be equal precedence to the |> pipeline operator, such that it can be used after a pipeline. The two above formattings are the only legal formattings.

If a pure handler is used with the new ?? "Result.withDefault" operator, we should raise a warning that the error mapping is unnecessary, since it will always be discarded by ??.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant