Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • Are you aware of the built-in filter() function? You don't even need to import it. Commented Jan 28 at 17:58
  • 1
    If the 'annoying extra work' is determining if something is a foo, either define and generate Foo objects and check with isinstance(object, Foo) or, if you prefer you can do something like create an Enum of foo, bar, baz and set a field on the emitted objects with the appropriate one. Commented Jan 28 at 18:04
  • By "annoying extra work", do you refer to the verbosity of the if statement (or even the need to define filterOnlyFoo); or do you refer to the work happening in the complicated logic of if ... something ...: bar = ... that you would like to optimise away when you know beforehand that you will only handle foos? Commented Jan 30 at 4:20