Programming languages enthusiast. Author of Learn Type Driven Development: https://www.packtpub.com/application-development/learn-type-driven-development
The answers there are good, but I want to add one more point: the 'map' operation is one that, in mathematics, makes some guarantees. Calling it 'map' in a programming language is a kind of a shortcut way of saying 'we make those guarantees too'. The overarching guarantee of 'map' is that its output data has the same 'structure' as its input data. E.g., if you map over an array with n elements, you get back an array with n elements. The structure is preserved.
'Map' can also be defined for other data structures, like linked lists, trees, graphs, sets, and so on. So that's the nice thing about it–if you come across that name, you can be reasonably sure that it's structure-preserving.
I would also add that programming adds to the original mathematics (without mentioning algebraic data structures) by enabling a data structure, such as an array, to be "mappable". That is, the data structure should support certain functions/methods which enable the map function to operate.
The details of course vary by language, but are crucial in enabling a generic map function to work with arrays, linked lists, trees, graphs, sets etc. So for Clojure, any data structure can be mapped if it implements 'first', 'rest' and 'cons'.
Which is weird to me, because I think of a physical map as changing the structure and keeping the data, and a mathematical/programming map to be keeping the structure and changing the data.
In my mind it would make more sense to map a linked list onto an array, or map an object onto an array, Object.values(someObject).
Programming languages enthusiast. Author of Learn Type Driven Development: https://www.packtpub.com/application-development/learn-type-driven-development
The answers there are good, but I want to add one more point: the 'map' operation is one that, in mathematics, makes some guarantees. Calling it 'map' in a programming language is a kind of a shortcut way of saying 'we make those guarantees too'. The overarching guarantee of 'map' is that its output data has the same 'structure' as its input data. E.g., if you map over an array with n elements, you get back an array with n elements. The structure is preserved.
'Map' can also be defined for other data structures, like linked lists, trees, graphs, sets, and so on. So that's the nice thing about it–if you come across that name, you can be reasonably sure that it's structure-preserving.
thanks for sharing this!
I would also add that programming adds to the original mathematics (without mentioning algebraic data structures) by enabling a data structure, such as an array, to be "mappable". That is, the data structure should support certain functions/methods which enable the map function to operate.
The details of course vary by language, but are crucial in enabling a generic map function to work with arrays, linked lists, trees, graphs, sets etc. So for Clojure, any data structure can be mapped if it implements 'first', 'rest' and 'cons'.
Which is weird to me, because I think of a physical map as changing the structure and keeping the data, and a mathematical/programming map to be keeping the structure and changing the data.
In my mind it would make more sense to map a linked list onto an array, or map an object onto an array,
Object.values(someObject)
.Also note that all the structures which can be mapped upon are called
functors
. That is a pretty important term in the fp worldI deliberately left out FP words :-)
Yep, not really necessary unless using a fp lang or a lib such as fp-ts, meant it to be more of a fun fact