繁体   English   中英

如何在 Coconut 中一个接一个地实现两种方法

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

Python

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.

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