suggestions icon indicating copy to clipboard operation
suggestions copied to clipboard

map.from_unique_list

Open CrowdHailer opened this issue 5 years ago • 5 comments

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

CrowdHailer avatar Jun 19 '20 07:06 CrowdHailer

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

lpil avatar Jun 19 '20 18:06 lpil

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

CrowdHailer avatar Jun 20 '20 06:06 CrowdHailer

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

lpil avatar Jun 20 '20 11:06 lpil

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

CrowdHailer avatar Jun 20 '20 12:06 CrowdHailer

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

lpil avatar Jun 20 '20 12:06 lpil