Closed yannham closed 3 weeks ago
I guess, if we do so, we can probably add a map
function as well, which is just fun f enum => enum |> std.enum.unwrap |> f |> std.enum.variant (std.enum.tag enum)
.
Another possibility for unwrap
would be to return the tag as well, like unwrap: Enum -> {tag | String, arg | optional}
.
Implemented in #1939.
Is your feature request related to a problem? Please describe. Nickel 1.5 introduced enum variants. Thanks to pattern matching and destructuring, there's a number of things you can do already, but there are still operations that are impossible to encore currently. Those operations are the transformations that are generic in the tag. Typically, one can't implement a function that takes a variant whose argument is a record, remove a field, and return the result in a variant with the same tag. That is:
Describe the solution you'd like
While pattern matching and destructuring is most principled (and typeable way) to manipulate enum when applicable, add functions to unwrap and to wrap the content of enum variants, that is:
The names are up for bikeshedding.