Why are the arguments ordered the way they are in Array.get
and Dict.get
? The order in most map/filter functions makes sense: the function comes before the collection (or monad, more generally).
MyCollection.map : (a -> b) -> MyCollection a -> MyCollection b
This makes it easier to compose higher functions out of smaller ones before passing in a collection.
Why, however, does the index/key come before the collection in get functions?
Dict.get : comparable -> Dict comparable v -> Maybe v
It seems to make it harder to compose higher functions. If the arguments were reversed, one could write:
ids : List Int
myObjects : Dict Int a
selectObjects = List.map (Dict.get myObjects) ids
But instead, the best way I can come up with to write this is:
ids : List Int
myObjects : Dict Int a
selectObjects = List.map (\id -> (Dict.get id myObjects)) ids
Am I missing something? What is the reason for the argument order in Array.get
, Dict.get
, and similar?