Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12409
| 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 | <ian.g.kelly@gmail.com> |
| 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 | <c57e2997-df9f-4d3c-be26-7cc8504dad47@s20g2000yql.googlegroups.com> |
| References | <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> <pan.2011.08.29.06.30.36.541000@nowhere.com> <c57e2997-df9f-4d3c-be26-7cc8504dad47@s20g2000yql.googlegroups.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Mon, 29 Aug 2011 11:42:51 -0600 |
| Subject | Re: Checking Signature of Function Parameter |
| To | Travis Parks <jehugaleahsa@gmail.com> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.548.1314639808.27778.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On Mon, Aug 29, 2011 at 10:45 AM, Travis Parks <jehugaleahsa@gmail.com> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Checking Signature of Function Parameter Travis Parks <jehugaleahsa@gmail.com> - 2011-08-28 14:20 -0700
Re: Checking Signature of Function Parameter Chris Angelico <rosuav@gmail.com> - 2011-08-29 07:31 +1000
Re: Checking Signature of Function Parameter Travis Parks <jehugaleahsa@gmail.com> - 2011-08-28 17:20 -0700
Re: Checking Signature of Function Parameter Chris Angelico <rosuav@gmail.com> - 2011-08-29 10:27 +1000
Re: Checking Signature of Function Parameter Ian Kelly <ian.g.kelly@gmail.com> - 2011-08-28 18:40 -0600
Re: Checking Signature of Function Parameter Chris Rebert <clp2@rebertia.com> - 2011-08-28 18:21 -0700
Re: Checking Signature of Function Parameter Nobody <nobody@nowhere.com> - 2011-08-29 07:30 +0100
Re: Checking Signature of Function Parameter Travis Parks <jehugaleahsa@gmail.com> - 2011-08-29 09:45 -0700
Re: Checking Signature of Function Parameter Ian Kelly <ian.g.kelly@gmail.com> - 2011-08-29 11:42 -0600
Re: Checking Signature of Function Parameter Travis Parks <jehugaleahsa@gmail.com> - 2011-08-29 11:04 -0700
Re: Checking Signature of Function Parameter Ethan Furman <ethan@stoneleaf.us> - 2011-08-29 16:36 -0700
csiph-web