Applying a filter

In this application, we're using a very simple filter. The entire filter process is embodied in the following function:

def anscombe_filter(        set_id: str, raw_data_map: Dict[str, List[Pair]]    ) -> List[Pair]:    return raw_data_map[set_id]

We made this trivial expression into a function for three reasons:

  • The functional notation is slightly more consistent and a bit more flexible than the subscript expression
  • We can easily expand the filtering to do more
  • We can include separate unit tests in the docstring for this function

While a simple lambda would work, it wouldn't be quite as convenient to test.

For error handling, we've done exactly nothing. We've focused on what's sometimes called the happy path: an ideal sequence of ...

Get Functional Python Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.