coconut
coconut copied to clipboard
Add haskell-like RecordWildCard syntax
See https://ocharles.org.uk/blog/posts/2014-12-04-record-wildcards.html
Example use case:
data Mydata(foo, bar)
foo = 1
bar = 2
new_data = Mydata({..})
Very useful for huge data structure that are e.g. tied to configuration, sql queries and so on.
I don't mind any other appropriate syntax other than {..}
I think python's *args
and **kwargs
solves a similar issue.
@cgarciae Possibly. The only case that isn't covered by *args
and **kwargs
is initializing the data
type based on local/global variables. With *args
you can use a list, and with **kwargs
you can use a dictionary, but you can't use the local/global scope (**globals()
and **locals()
won't work, since the constructor will reject keys that don't correspond to arguments). What I'm not sure of, though, is how useful that use case actually is, and thus whether the feature would really be worth implementing.