Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!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.026 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'anyway.': 0.05; 'subject:Function': 0.09; 'def': 0.12; 'base64': 0.16; 'in-place': 0.16; 'map(int,': 0.16; 'wrote:': 0.18; "python's": 0.19; 'skip:1 30': 0.19; 'skip:f 30': 0.19; 'example': 0.22; 'import': 0.22; 'define': 0.26; 'header:In-Reply-To:1': 0.27; 'skip:p 30': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'easier': 0.31; 'forces': 0.31; 'could': 0.34; 'subject: (': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'chain': 0.60; 'new': 0.61; 'making': 0.63; 'extent.': 0.84; 'x):': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=Cn/DwBxNDBLItTA+V5RMju87H2PM3E2BuQ9UAZX0hzs=; b=Gm9GAN9KjVp32C+lqAi4jGGlo1bqPNmmEvBpK2NKK/1Mko4wZZkrmKGLrfm5k/cZpZ wH4WvH1G8e1g103NpJe2qfbPI5UeWAAbiGJXCljeMBcF3YRAsyexFE9G/HKv8+JXO1mM g3oVTE+mFHNxbOVyHGKEeU1aJOE6obr2hLWPlyxN9nf2BfRkBnosDXHcYJKKbZPUIiAI kVIx/YBh8fGU57ukqyKR66uIIV45FmkjpoXwCqxdl8kBnK6D/7DQHlj/QT3MtZNyUa5Q DtSB1CLEhOExg4Vp9USOIFbafv/zmqM4+xPJDc0MqImadiCpj/MYqc7xdTvX+4xfhjRA bBBg== X-Received: by 10.236.221.133 with SMTP id r5mr2152532yhp.113.1402246523047; Sun, 08 Jun 2014 09:55:23 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <12d31393-3598-4304-8ce9-ac847ac21c64@googlegroups.com> References: <8b96ae27-20fa-4df9-807e-c806fed983c0@googlegroups.com> <38058e64-0113-457c-ae63-cc66e8b569cd@googlegroups.com> <12d31393-3598-4304-8ce9-ac847ac21c64@googlegroups.com> From: Ian Kelly Date: Sun, 8 Jun 2014 10:54:42 -0600 Subject: Re: Uniform Function Call Syntax (UFCS) To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 1402246524 news.xs4all.nl 2882 [2001:888:2000:d::a6]:43804 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72975 On Sun, Jun 8, 2014 at 10:24 AM, jongiddy wrote: > A contrived example - which of these is easier to understand? > > from base64 import b64encode > > # works now > print(b64encode(str(min(map(int, f.readlines()), key=lambda n: n % 10)), b'?-')) > > # would work with UFCS > f.readlines().map(int).min(key=lambda n: n % 10).str().b64encode(b'?-').print() I prefer not making it a one-liner: data = map(int, f.readlines()) min_data = min(data, key=lambda n: n % 10) print(b64encode(str(smallest_data), b'?-')) Python's standard of having in-place methods return None also forces this to an extent. Whenever you want to tack on something like .append(), that's the end of your chain and it's time to start a new line anyway. Of course, you could always define something like: def appended(iterable, x): result = list(iterable) result.append(x) return result and use that in your chain.