[英]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.