【问题标题】:How to implement two methods one after the other in Coconut如何在Coconut中一个接一个地实现两个方法
【发布时间】:2021-10-02 23:12:53
【问题描述】:

coconut documentation中提供的示例

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()

【问题讨论】:

    标签: python machine-learning methods functional-programming coconut


    【解决方案1】:

    如果你真的想为此使用管道,你可以使用statement lambda 来做

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

    虽然 Python 代码也可以在 Coconut 中正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-09
      • 1970-01-01
      • 2020-12-08
      • 1970-01-01
      • 2013-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多