Skip to content

Instantly share code, notes, and snippets.

@jahfer

jahfer/generator-to-map.js

Last active Aug 29, 2015
Embed
What would you like to do?
Messing with ES6 Map + Generator
const ENDKEY = Symbol('endOfMap');
function* simpleGen() {
let counter = 0
while (counter++ < 3) {
yield [counter, true]
}
yield [ENDKEY, false]
}
let gen = simpleGen() // iterable!
let map = new Map(gen) // takes an iterable!
for (let [key, value] of map.entries()) {
console.log(key, value)
}
// 0 true
// 1 true
// 2 true
// Symbol(endOfMap) false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.