tweag / nickel

Better configuration for less
https://nickel-lang.org/
MIT License
2.23k stars 85 forks source link

Add from/to_tag_and_arg #1939

Closed yannham closed 3 weeks ago

yannham commented 4 weeks ago

Depends on #1937.

This PR adds two functions to convert enums to and back from records, represented as a tag and an optional argument. Such functions are useful to handle enums in a general, dynamic way, while pattern matching requires to know in advance the possible tags. They might prove useful if we have an export_with metadata or the like, one day.

Additionally, we also implement a map function, which can be derived from the conversions but is useful in its own right.

As far as naming is concerned, we initially hesitated with to_record and from_record, but this doesn't really give a hint as to what is the conversion. tagged_value was also considered, but in some sense an enum is a tagged value as well, so it's not telling much. I initially picked to/from_tag_and_value, but I think we are using the term "argument" pretty much everywhere else when talking about enum variants (in particular because the syntax is application-like, so it makes sense that arg is an argument in 'Foo arg), so I switched to keep a consistent jargon.

dpulls[bot] commented 3 weeks ago

:tada: All dependencies have been resolved !

yannham commented 3 weeks ago

@jneem gentle ping in case it went under the radar, as this is the last PR to review and merge before cutting the next release :slightly_smiling_face: