Note that this is the compiled-to-ES5 version.
Iterators represent a stream of data. To get the next value in the
stream, you call the iterator's
next method. This
enables both lazy and infinite sequences. Most
of the time you don't need to call
yourself: when you use a for-of loop, you're using iterators
behind the scenes.
Anything can create iterators — they just need to make an
object with the proper
next interface — but
generator functions and the
yield expression provide
convenient syntactic sugar.
wu.js provides the higher order functions you've come
to love from working with arrays (such
filter) as well as ones
we can rewrite the above example like this:
The following is a simple immutable sorted set implementation that doesn't do tree balancing for simplicity. It has an iterator method which yields items in sorted order.
We can initialize a set of 100 random floats to work with:
To get the sum of all elements greater than .8 in the set:
To find the number of elements that are less than .25:
To find the first element whose square is greater than .5:
Development happens on GitHub. Include test(s) and documentation updates in your pull requests.
File bugs and feature requests in the GitHub issue tracker. When filing bugs, include:
wu.js and its tests to ES5 using the Babel compiler,
$ npm run build
This command regenerates:
dist/wu.js— The ES5 compatible version of
dist/wu.debug.js— The ES5 compatible version of
wu.jswith an inline source map included.
dist/wu.min.js— The minified ES5 compartible version of
$ npm test
This documentation is created with the static site generator Jekyll. To set up jekyll, run:
$ gem install jekyll bundler $ cd path/to/wu.js $ bundle install
Once Jekyll is set up, to serve the docs locally and automatically recompile them on change, run:
$ npm run docs
The documentation will be served at http://0.0.0.0:4000.
The sources for this documentation live in
and markdown files in the
wu method has its own markdown file
_posts directory, and the table of contents
wu methods is generated automatically. The CSS
styles live in