3 ms·
Use map(key). I learnt this "map as callable" idea fron clojure and wondered why it is not more common.
by xiaq 11y ago
Use map(key). I learnt this "map as callable" idea fron clojure and wondered why it is not more common.
- epidemian 11y agoYeap. I find it very elegant to be able consider maps as simply functions that map elements from one domain to another: a -> b. A set can then simply be consider a special case of map: a -> Bool. A definition like that can also make concepts like infinite sets much easier to conceive. It'd be nice to be able to express "the set of all prime numbers" or "a map between a person and their soul-mate: Peson -> Maybe(Person)" and have them be interchangeable with other Sets and Maps (of same type) on general operations like intersection, difference, etc. But i think this interpretation is at odds with the idea of maps and sets being data structures of a given size, where you add and remove things.