返回介绍

前言

发布于 2019-05-31 13:12:50 字数 2084 浏览 1008 评论 0 收藏 0

Lazy.js is a lazy evaluation library for JavaScript.

This has been done before. For examples see:

However, at least at present, Lazy.js is faster (on average) than any of those libraries. It is also more complete, with nearly all of the functionality of Underscore and Lo-Dash.

Finding your way around the code

At the heart of Lazy.js is the Sequence object. You create an initial sequence using Lazy, which can accept an array, object, or string. You can then "chain" together methods from this sequence, creating a new sequence with each call.

Here's an example:

var data = getReallyBigArray();

var statistics = Lazy(data)
  .map(transform)
  .filter(validate)
  .reduce(aggregate);

Sequence is the foundation of other, more specific sequence types.

An ArrayLikeSequence provides indexed access to its elements.

An ObjectLikeSequence consists of key/value pairs.

A StringLikeSequence is like a string (duh): actually, it is an ArrayLikeSequence whose elements happen to be characters.

An AsyncSequence is special: it iterates over its elements asynchronously (so calling each generally begins an asynchronous loop and returns immediately).

For more information

I wrote a blog post that explains a little bit more about Lazy.js, which you can read here.

You can also create an issue on GitHub if you have any issues with the library. I work through them eventually.

@dtao

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文