Functional pipes in python like %>% from R's magritrr

后端 未结 14 2209
春和景丽
春和景丽 2020-11-29 16:17

In R (thanks to magritrr) you can now perform operations with a more functional piping syntax via %>%. This means that instead of coding this: <

14条回答
  •  死守一世寂寞
    2020-11-29 16:54

    If you just want this for personal scripting, you might want to consider using Coconut instead of Python.

    Coconut is a superset of Python. You could therefore use Coconut's pipe operator |>, while completely ignoring the rest of the Coconut language.

    For example:

    def addone(x):
        x + 1
    
    3 |> addone
    

    compiles to

    # lots of auto-generated header junk
    
    # Compiled Coconut: -----------------------------------------------------------
    
    def addone(x):
        return x + 1
    
    (addone)(3)
    

提交回复
热议问题