Skip to content

sashee/infinite-collections-with-es6-generators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Infinite collections with ES6 generators

This repo contains some demonstration code samples on how to use ES6 generators.

Read more at https://advancedweb.hu/2016/05/31/infinite-collections-with-es6-generators/ .

Iterators

Hand-creating iterators requires boilerplate, but it is the basis for generators. You can create infinite collections easily.

http://sashee.github.io/infinite-collections-with-es6-generators/iterator.html

Generators

Generators are syntax sugar on top of iterators, but they make them a whole lot simpler and readable.

http://sashee.github.io/infinite-collections-with-es6-generators/generators.html

Infinite collections

Infinite collections come handy when you don't know how many elements you'll need in advance. This sample demonstrates this problem.

When you want to sum the first 100 positive numbers, you know you'll need 100 elements. But what if you want to sum the first 100 primes?

http://sashee.github.io/infinite-collections-with-es6-generators/primes.html

Gentoo library

You can create infinite collections using generators. With the help of the Gentoo library (among others) you can write terse and readable functions.

http://sashee.github.io/infinite-collections-with-es6-generators/gentoo.html