Stream: ideas

Topic: Dict.update alter fn work with a Result?


view this post on Zulip Stuart Hinson (Sep 19 2024 at 20:58):

As the title suggests, I wonder if the alter fn passed to Dict.update would be easier to work with if it were passed a Result rather than [Present v, Missing] value so the various Result functions could be used.

Thoughts? Happy to make a PR if there's agreement!

view this post on Zulip Sam Mohr (Sep 19 2024 at 21:02):

I agree that we are putting all of our chips into the ergonomics of Result, and it can be represented this way

view this post on Zulip Sam Mohr (Sep 19 2024 at 21:03):

So yes, using Result v [Missing] would compose better, I'm on board

view this post on Zulip Brendan Hansknecht (Sep 19 2024 at 21:16):

Sounds fine. Though I'm not sure it will help that much
Generally speaking you will want to handle the found and missing cases separately with a when ... is anyway. But sometimes you may just want to use withDefault. So yeah, sounds reasonable to me.

view this post on Zulip Sam Mohr (Sep 19 2024 at 21:17):

I think you mean ??, the new sexy version

view this post on Zulip Brendan Hansknecht (Sep 19 2024 at 21:22):

True

view this post on Zulip Brendan Hansknecht (Sep 20 2024 at 01:37):

If you want to be super nice updating any uses of Dict.update in other roc repos would be amazing. I kinda doubt it is really used anywhere though. Found one examples: https://github.com/roc-lang/examples/blob/5d4898e5d63aefa96155d2f4f6312b3517bbbf1a/examples/BasicDict/BasicDict.roc#L47

view this post on Zulip Sam Mohr (Sep 20 2024 at 03:25):

Seems like there are 73 Roc files with Dict.update in them: https://github.com/search?q=Dict.update%20path%3A*.roc&type=code

view this post on Zulip Sam Mohr (Sep 20 2024 at 03:25):

It would probably be a lot of work to all of them. Maybe ones recently updated, but ignoring out of date ones

view this post on Zulip Brendan Hansknecht (Sep 20 2024 at 03:27):

I wouldn't worry about anything advent of code or 3rd party. Just core roc-lang/...

view this post on Zulip Brendan Hansknecht (Sep 20 2024 at 03:28):

https://github.com/search?q=Dict.update+path%3A*.roc+org%3Aroc-lang&type=code

view this post on Zulip Brendan Hansknecht (Sep 20 2024 at 03:30):

I guess we can toss a note over to #announcements once this lands.

view this post on Zulip Stuart Hinson (Sep 20 2024 at 11:18):

Good call, added a couple PRs to track the change

https://github.com/roc-lang/examples/pull/208
https://github.com/roc-lang/unicode/pull/20


Last updated: Jun 16 2026 at 16:19 UTC