Lazy List
Functional Lazy List, lightweight implimented via ES6 generator.
Demo
> console 1 2 3 > console 10 11 12 13 14 15 16 17 18 19 > console 3 5 7 11 13 17 19 23 29 31 > console 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 > console 10 11 12 13 14 0 1 2 3 4 > console 1 2 3 > console3 > console2 > console 1 2 2 3 4 4 5 1 3 > console '1': 1 1 '2': 2 2 '3': 3 3 '4': 4 4 '5': 5 > console > consoletrue > consolefalse > consolefalse > consoletrue > console 0 1 2 > console 2 3 > console 1 2 > console
Most Possible Abuse
map
to do side effect.
use you should never do side effect in the argument function of map
or any other decorators/combiners. if you want to enumerate a LazyList to do something, for ... of
syntax is exactly what you want.
ie. lots of people used to do things like this:
it is strongly recommended that you use for ... of
instead:
for let x of console
The abuse of map
will make thing unclear since map
is designed to return a LazyList and changes nothing else. Actually the map
one won't work since the mapping function is not called immediately.
And for ... of
is designed to enumerate items in a LazyList and do side effects.
Do right things in right way keeps bugs away.
Install
install & require in nodejs
- install with npm:
your/repo/> npm install lazy-list
- require:
const L = require('lazy-list')
- require separately:
const {map, filter} = L