以不同方式提供链接的函数的命名建议

发布于 2024-09-02 04:42:16 字数 408 浏览 3 评论 0原文

我编写了一个实验函数,该函数通过使用高阶函数使传递的对象可链接。现在它的名字是“chain”,这是一个使用示例;

chain("Hello World")
  (print) // evaluates print function by passing "Hello World" object.
  (console.log,"Optional","Parameters")
  (returnfrom) // returns "Hello World"

它看起来很 lispy,但行为却非常不同,因为它是用基于 C 的语言编码的,我不知道这个习惯用法是否有一个名称,而且我找不到比“链”更合适的名称。

有什么想法、建议吗?

编辑:“with”听起来非常合适的名字,但它是我正在使用的语言中的保留词。

I've coded an experimental function which makes passed objects chainable by using high order functions. It's name is "chain" for now, and here is a usage example;

chain("Hello World")
  (print) // evaluates print function by passing "Hello World" object.
  (console.log,"Optional","Parameters")
  (returnfrom) // returns "Hello World"

It looks lispy but behaves very different since it's coded in a C based language, I don't know if there is a name for this idiom and I couldn't any name more suitable than "chain".

Any ideas, suggestions?

edit: "with" sounds very suitable name but it's a reserved word in the language I'm working on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里兽 2024-09-09 04:42:16

这种 API 设计模式通常称为Fluent 界面

更新: 流畅接口的实际实现是否采用面向对象语言是无关紧要的。这是传递上下文以实现“代码流”感觉的模式,这似乎正是您想要做的。

当然,模式名称实际上并不能回答您的问题。 :-)

正如您所指出的,命名实际函数的最佳选择是 with。第二好的方法是使用

This API design pattern is usually called a Fluent interface.

Update: Whether the actual implementation of a fluent interface is in object-oriented language is irrelevant. It's the pattern of passing a context to achieve the feeling of a "code flow", which seems exactly what you are aiming to do.

Of course, what the pattern name is does not actually answer your question. :-)

As you noted, the best choice for naming your actual function would be with. Second best would be using.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文