[Python-ideas] add fluent operator to everything

Jimmy Girardet ijkl at netc.fr
Tue Feb 19 09:13:14 EST 2019


Hi,

There was the discussion about vector, etc...

I think I have a frustration about chaining things easily in python in
the stdlib where many libs like orm  do it great.

Here an example :

The code is useless, just to show the idea

>>> a = [1,2,3]

>>> a.append(4)

>>> a.sort()

>>> c = max(a) + 1


I would be happy to have

>>> [1,2,3].append(4)::sort()::max() +1

It makes things very easy to read: first create list, then append 4,
then sort, then get the max.

To resume, the idea is to apply via a new operator (::, .., etc...) the
following callable on the previous object. It's clearly  for standalone
object or after a method call when the return is None (there is fluent 
`.` when there is a return value)

>> object::callable()  = callable(object)
>> object(arg)::callable = callable(object(arg))

def callable(arg1,arg2):
   pass

>> object::callable(arg) == callable(object, arg)

The idea is to use quite everything as first argument of any callable.

I do not know if it was already discussed, and if it would be
technically doable.

Nice Day
Jimmy



More information about the Python-ideas mailing list