在 CoffeeScript 中处理无限列表
在 Haskell 中,我可以这样做来处理无限列表。
takeWhile (<1000) [1 ..]
CoffeeScript 有办法做到这一点吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
在 Haskell 中,我可以这样做来处理无限列表。
takeWhile (<1000) [1 ..]
CoffeeScript 有办法做到这一点吗?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
StreamJS 允许在 JavaScript 中创建“无限”列表。
使用它的(粗略的)coffeescript 端口:
StreamJS enables the creation of 'infinite' lists in javascript.
Using it's (rough) coffeescript port:
不像原语那样内置,但它们可以像大多数其他语言一样被黑客入侵。至少有人在 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/ .