在 CoffeeScript 中处理无限列表

发布于 2024-12-29 00:17:48 字数 120 浏览 4 评论 0 原文

在 Haskell 中,我可以这样做来处理无限列表。

takeWhile (<1000) [1 ..]

CoffeeScript 有办法做到这一点吗?

In Haskell I can do this to handle an infinite list.

takeWhile (<1000) [1 ..]

Is there a way to this in CoffeeScript?

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

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

发布评论

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

评论(2

剑心龙吟 2025-01-05 00:17:48

StreamJS 允许在 JavaScript 中创建“无限”列表。

使用它的(粗略的)coffeescript 端口

# Stream.range() creates a list from 1...Infinity
numbers = Stream.range().until (x) -> x > 1000

StreamJS enables the creation of 'infinite' lists in javascript.

Using it's (rough) coffeescript port:

# Stream.range() creates a list from 1...Infinity
numbers = Stream.range().until (x) -> x > 1000
梨涡少年 2025-01-05 00:17:48

不像原语那样内置,但它们可以像大多数其他语言一样被黑客入侵。至少有人在 CoffeeScript 中尝试过它;请参阅 https://github.com/swannodette/fun.coffee/ blob/master/src/fun.coffee 。对于看起来不太“黑入”的解决方案,您可能需要阅读 CPS 并支持正确的尾部调用,请参阅 http://blog.mozilla.com/dherman/2011/01/30/proper-tail-calls-in-harmony/

Not as built in primitives, but they can be hacked in as in most other languages. At least someone is toying around with it in CoffeeScript; see https://github.com/swannodette/fun.coffee/blob/master/src/fun.coffee . For solutions that seem less "hacked in", you might want to read up on CPS and support for proper tail calls, see http://blog.mozilla.com/dherman/2011/01/30/proper-tail-calls-in-harmony/ .

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