简体   繁体   English

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

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

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

If you really want to use pipes for this, you can use a statement lambda to do如果你真的想为此使用管道,你可以使用语句 lambda来做

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

though the Python code will also work in Coconut just fine.尽管 Python 代码也可以在 Coconut 中正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Kivy:绑定两个方法,一个接一个地调用 - Kivy: bind two methods to be called one after the other 如何让selenium一个接一个地执行两个不同的按钮 - How to make selenium execute two different buttons one after the other 如何在 manimce 中一个接一个地应用两个转换? - How to apply two tranformations one after the other in manimce? 如何在 python 中实现给定两个协程,保持运行一个直到另一个完成 - How to implement in python given two coroutine, keep run one until the other finished 如何基于 CPLEX 上的其他两个约束实现新约束? - How to implement a new constraint based on two other constraints on CPLEX? 单击按钮时两个功能一个接一个-Pyside - Two function one after the other when clicked pushbutton - Pyside 插补其中一列以适合另一列之后,不能减去两列。 - Cannot subtract two columns after one was interpolated to fit the other. 拟合两条 voigt 曲线,一个接一个使用 lmfit - Fitting two voigt curves, one after the other using lmfit 如何一个接一个地查找重复的字符串? - How to find repeating strings one after the other? 如何创建一个继承其他两个类的方法的类,并将其自己和方法共享给它们 - How do I create a class that inherits methods from two other classes and shares own and their methods back to them
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM