当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

前言

优质
小牛编辑
137浏览
2023-12-01

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