Hi! I'm wondering if the following is something I can represent in Roc's type system:
swapTag : [a, b]x, a, b -> [b]x
swapTag = \tag, match, replace -> when tag is
match -> replace
_ -> tag
Essentially, this would be a rather abstract function that expects a tag union which can contain a tag which should be replaced if present, but otherwise pass through the input tag unmodified. A variation on such a thing could be useful for rote error elimination in a Result ("consider this particular error a non-error, and supply this Ok value if found"), particularly in cases where Result.onErr
is tedious. There are other cases beyond error handling in which I might want a concise capability to this effect.
Last updated: Jul 05 2025 at 12:14 UTC