5 ms·
> The use case I had in mind was specifically how people will use `Keyword.get` to grab configuration values or options. It seems like this advice is very depe
by jolux 5y ago
> The use case I had in mind was specifically how people will use `Keyword.get` to grab configuration values or options.
It seems like this advice is very dependent. I think you should decide whether a function accepts maps or keyword lists or both, but I do not think that all functions which operate on key-value structures should default to accepting both. They have very different performance characteristics, and keys are not unique in keyword lists.
- keathley 5y agoI agree on the performance characteristics. But if your using `get` then it doesn't matter that keyword lists have non-unique keys. You just get the first one.
- jolux 5y agoMaybe it does, maybe it doesn’t. Maybe somebody gave you a keyword list that they thought had unique keys and it didn’t. The point is, the two structures are not semantically equivalent, and I think it’s a mistake to conflate them in general. Just because you can use access syntax on both doesn’t mean you should write a polymorphic function that does so. Sometimes you should! But not most of the time.
- keathley 5y agoNo, it literally returns you the first one. If you have a keyword list and use get your not going to be getting the benefit of duplicate keys.
- deleted 5y ago[deleted]
- jolux 5y agoNo, you asserted it doesn't matter because it still works and returns the first value. I was saying it might. The point stands. Different data structures, different modules, different semantics. Can and should is an important distinction here.