Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you do method chaining?
#3
Yeah, that gives the same results, but it was just a toy class to demonstrate where it could syntactically be useful.  
What if each filter was unrelated from the others?  Like, what if it's a wrapper around BeautifulSoup, and each query is a sub-selector of the parent filter's result?

The original example could also be written like this, though I think using backslashes looks worse than the dangling parentheses...
things = query(range(1000)) \
   .where(lambda x: x % 2 == 0) \
   .where(lambda x: x % 3 == 0) \
   .where(lambda x: x % 4 == 0) \
   .where(lambda x: x % 5 == 0)
Reply


Messages In This Thread
How do you do method chaining? - by nilamo - May-01-2017, 02:36 AM
RE: How do you do method chaining? - by Mekire - May-01-2017, 06:36 AM
RE: How do you do method chaining? - by nilamo - May-01-2017, 02:01 PM
RE: How do you do method chaining? - by volcano63 - May-01-2017, 04:06 PM
RE: How do you do method chaining? - by nilamo - May-01-2017, 04:34 PM
RE: How do you do method chaining? - by Mekire - May-01-2017, 10:19 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020