is that place near these other places? (in python)

functional programming way of finding whether a place is within a certain distance of several other places. roughly, in python.

from geopy import distance

class Place:

  # lots of code omitted

  def near(self, distance, others):
    any = lambda a, b: a or b # NOTE: use "a and b" for something different
    near = lambda p: self.distance(p).miles < = distance.miles
    return reduce(any, map(near, others))

used thusly:

Place('24th and mission, sf, ca').near(distance(1), [ Place('16th and valencia, sf, ca') ])

About this entry