Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12409
| 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 | 2011-08-29 11:42 -0600 |
| Subject | Re: Checking Signature of Function Parameter |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.548.1314639808.27778.python-list@python.org> (permalink) |
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