简体   繁体   中英

How to implement two methods one after the other in Coconut

Example provided in coconut documentation

obj |> .attribute |> .method(args) |> func$(args) |> .[index]

However i would like to know how can we apply two methods one after the other that do not return anything, they just modify the object

For example:

Coconut

(
    data
    |> Model
    |> .fit()      # does not return anything
    |> .summary()  # therefore, this throws an error
)

Python

m = Model()
m.fit()
m.summary()

If you really want to use pipes for this, you can use a statement lambda to do

m = (
    data
    |> Model
    |> (def m -> m.fit(); m)
    |> .summary()
)

though the Python code will also work in Coconut just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM