Nobody *ever* uses map, et. al… (example 2)
Today’s Nobody *ever* uses post.
require "netaddr.rb"
CIDR_ADDRESSES = ["192.0.2.1/24", "..."].map {|address| NetAddr::CIDR.create(address)}
in_range = CIDR_ADDRESSES.any? {|address| address.contains?("192.0.2.1")}
But of course nobody ever does this…
Interestingly, in Python3000 they are kinda deprecating map().
They would rather people use for comprehensions (which are very like scalas). So its not that they don’t like the functional aspect…
still it confuses me, map seems like such an intuitive thing to want to do in a very human sense. Maybe its the word “map” that has been overloaded.
Michael Neale
8 Jul 08 at 2:28 pm
The term map comes from the notion of a functor (Category Theory). Here is the true signature for map:
(x -> y) -> Fx -> Fy
Remember that -> is right associative, so:
(x -> y) -> (Fx -> Fy)
“Takes a transformation x to y and ‘lifts’ it into an environment F”. Functors are in very common use in programming (just for different values of F) whether they are explicitly coded that way or not. Function composition being quite possibly the most common - how often do you compose 2 functions?
Interestingly, this is why Haskell’s lambdabot will @pl your equation to use lots of (.) which denotes functor map (it is not specialised to composition in lambdabot).
Assume the position, “the Python kids have no clue what they are doing” and everything starts to make a lot of sense
Tony Morris
20 Jul 08 at 9:06 am