streamjs和linqjs之间有什么关系?[英] What's the relationship between streamjs and linqjs



读完SICP,最近发现streamjs.开发人员引用 linqjs 作为具有不同语法的替代实现,但我无法建立连接.streamjs 中的方法如何映射到 linqjs 中的方法?


我没有使用过这两个库,但是,这是我的初步分析(我已经阅读了相当多的 SICP,但不可否认的是全部内容).

stream.js 是列表的函数式数据结构的实现.函数式语言中的许多数据结构往往是递归的,很像 Stream 结构.它由一个头部元素和一个用于尾部(后续元素)的 Stream 组成.在这里,可以通过允许尾部为函数(即无限序列)来实现惰性求值.

现在,为了回答您的问题,linq.js 提供的所有函数都应该能够使用其他常见的高阶函数(如 map、reduce、walk、fold 等)来定义.

当然,stream.js 没有实现 linq.js 中的 Any() 方法,但您可以使用 reduce() 来实现.



After reading SICP, I recently discovered streamjs. The developer referenced linqjs as an alternate implementation with different syntax, but I can't make the connection. How do the methods in streamjs map to those in linqjs?


I haven't used either library, but, here's my initial analysis (I've read quite a bit of SICP, but not the whole thing admittedly).

stream.js is an implementation of a functional style data structure for a list. Many data structures in a functional language tend to be recursive, much like the Stream structure. It is composed of a head element, and a Stream for the tail (subsequent elements). Here, lazy evaluation can be achieved by allowing the tail to be a function (i.e. infinite sequences).

Now, to answer your question, all of the functions provided by linq.js should be able to be defined with other common higher order functions like map, reduce, walk, fold, etc.

Sure, stream.js does not implement the Any() method from linq.js, but you can just do that with reduce().