[英]How to implement two methods one after the other in Coconut
椰子文檔中提供的示例
obj |> .attribute |> .method(args) |> func$(args) |> .[index]
但是我想知道我們如何一個接一個地應用兩個不返回任何內容的方法,它們只是修改對象
例如:
(
data
|> Model
|> .fit() # does not return anything
|> .summary() # therefore, this throws an error
)
m = Model()
m.fit()
m.summary()
如果你真的想為此使用管道,你可以使用語句 lambda來做
m = (
data
|> Model
|> (def m -> m.fit(); m)
|> .summary()
)
盡管 Python 代碼也可以在 Coconut 中正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.