Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python': 0.08; 'comfortably': 0.09; 'inclined': 0.09; 'subject:Function': 0.09; 'am,': 0.12; 'def': 0.15; '10:45': 0.16; 'lambda': 0.16; 'parks': 0.16; 'squares': 0.16; 'subject:Checking': 0.16; 'travis': 0.16; 'two.': 0.16; 'cc:addr:python-list': 0.16; 'mon,': 0.16; 'this:': 0.16; 'wrote:': 0.16; 'cheers,': 0.18; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'similarly': 0.23; 'aug': 0.24; 'raise': 0.28; 'bit': 0.28; 'looks': 0.29; 'message-id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.30; 'received:209.85.161.46': 0.31; 'received:mail- fx0-f46.google.com': 0.31; 'does': 0.32; 'too': 0.33; 'try:': 0.34; 'received:209.85.161': 0.35; 'think': 0.38; 'allows': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'skip:1 10': 0.63; '29,': 0.67; 'compose': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=jEtCNMZ7e4ve2DGMw3JEbsmFdpDdur4q+bQNrDnvni8=; b=TVMkVtBEAatH67BoZxpLttiuze7pyAeHk/HNkuHCq32rr9LOiKXGZ6KN/mVg1HoUCm BqnbiUx4t+Cvqu7GqJtaTSBrdzfdoAI7ZR/haYaumMCy9q3RCBV5X0WGXNvkn3Yr0KkI x+aljpn036XghpivIL7CyVrMrDPWUwrCN5UL8= MIME-Version: 1.0 In-Reply-To: References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> From: Ian Kelly Date: Mon, 29 Aug 2011 11:42:51 -0600 Subject: Re: Checking Signature of Function Parameter To: Travis Parks Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314639808 news.xs4all.nl 2422 [2001:888:2000:d::a6]:55371 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12409 On Mon, Aug 29, 2011 at 10:45 AM, Travis Parks wrote: > I wanted to allow for calls like this: > > extend(range(0, 1000)).map(lambda x: x * x).where(lambda x: x % 2 == > 0).first(lambda x: x % 7 == 0) > > It allows me to compose method calls similarly to LINQ in C#. I think > this looks better than: > > first(where(map(range(0, 1000), lambda x: x * x, lambda x: x % 2 == 0, > lambda x : x % 7 == 0))) FWIW, I would be inclined to write that in Python like this: def first(iterable): try: return next(iter(iterable)) except StopIteration: raise ValueError("iterable was empty") squares = (x * x for x in range(0, 1000)) first(x for x in squares if x % 14 == 0) It does a bit too much to comfortably be a one-liner no matter which way you write it, so I split it into two. Cheers, Ian