gleam-lang / suggestions

📙 A place for ideas and feedback
26 stars 2 forks source link

map.from_unique_list #74

Open CrowdHailer opened 4 years ago

CrowdHailer commented 4 years ago

A function that will turn a list to a map or return an error if a duplicate key is found.

from_unique_list: fn(List(tuple(key, value))) -> Result(Map(key, value), key) 

Returned error value is the first key

lpil commented 4 years ago

This isn't a function I've used before- is there precedence in other languages' standard libraries? What's the use case?

CrowdHailer commented 4 years ago

The usecase is in http query strings being able to show a user an error for parameters that shouldn't be declared twice but where

lpil commented 4 years ago

I've had a look around but I can't find any existing languages with this function- do you know of any?

CrowdHailer commented 4 years ago

No, but I my experience most applications don't actually show duplicate keys as a warning. so at some level it is missing. Quite happy for this to be something that lives in my parameters library for a while

lpil commented 4 years ago

Let's keep it there for now, and we can promote it if it turns out to be commonly useful.