Many points of view are mine:
We can consider all map functions / methods as specific cases of Haskell fmap functors . From this definition, it can be assumed that the structure will be preserved (plus some other interesting properties).
But in .NET there are no Typeclasses, so we can define a map over "restricted functors", the consequence of which is Functor properties will not be saved, but since there is no common code that will be affected, the impact will be limited.
Therefore, nothing prevents us from defining map over:
- Sets (restriction: the function must be "a →" b, when "a" and "b": comparison must be injective )
- Strings (restriction: the function must be char -> char)
- Nullables (restriction: the function must be "a →" b, where "b is not a reference type")
Please note that in some cases there are restrictions both at the type level and at the level of values, for example, for sets, the restriction at the level level is both types: "a" and "b" must have a comparison, while the restriction over The value of the function is that the function should be injective .
If the language is capable of expressing type level restrictions, the compiler will throw an error if these requirements are not met.
There are no compilation time limits for function values, although we can create unit tests if we want to make sure that they are correct. But what happens if we do not care about limiting these functions?
Well, if we understand that some Functor properties will not be respected, there is nothing wrong with using a map over a limited Functor .
Thus, we can define a map over structures such as sorted lists, of course, we cannot assume that map a >> map b will always be equivalent to map (a >> b) in these cases. The limitation here is that the function must increase monotonously .
NOTE. For Haskell, there is a package with a restricted functor and an instance for Sets