Is it a good idea to have a syntax sugar to function composition in Python?

后端 未结 4 666
我寻月下人不归
我寻月下人不归 2021-02-05 08:37

Some time ago I looked over Haskell docs and found it\'s functional composition operator really nice. So I\'ve implemented this tiny decorator:

from functools im         


        
4条回答
  •  有刺的猬
    2021-02-05 09:07

    IMHO: no, it's not. While I like Haskell, this just doesn't seem to fit in Python. Instead of (f1 >> f2 >> f3) you can do compose(f1, f2, f3) and that solves your problem -- you can use it with any callable without any overloading, decorating or changing the core (IIRC somebody already proposed functools.compose at least once; I can't find it right now).

    Besides, the language definition is frozen right now, so they will probably reject that kind of change anyway -- see PEP 3003.

提交回复
热议问题