Hacker News new | past | comments | ask | show | jobs | submit login

Not GP, but: You can't use trivially use [] dereferencing notation with structs, or, for that matter get_in or put_in, without first making it access protocol compliant (which maybe you shouldn't do? I haven't figured that out for myself yet). A common use case for me is initializing a GenServer with a kwl, which is nice for your code prettiness, but you'd like to also support maps, because that fits with how the internal state of the GenServer looks. Then when you go to refactor your GenServer to use a struct because you prefer a more solid typesystem, you can run into a minor stumbling block and slightly uglier code. Not insurmountable though, and you're writing tests right? Once those tests pass you've got nothing to worry about.



Making the conversion from/to Map and (keyword) list explicit makes sense, as they have very different access patterns: keyword lists really are not suited for random access unless very small.

And in general Erlang and Elixir have very little automatic type conversions, if any.

But maps and structs are interchangeable, I don't get why using one or the other would make your GenServer code any different. A struct is just a map with an additional field called "__struct__".




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: