Skip to content

Instantly share code, notes, and snippets.

@ljharb ljharb/test.js Secret
Created Jul 17, 2019

Embed
What would you like to do?
function* g() {
let i = 0;
while (i++ < 4) {
console.log(i);
yield i;
}
console.log('done');
}
function mapper(x) {
console.log('map', x);
return x * 2;
}
Array.from(g(), mapper);
/*
1
map 1
2
map 2
3
map 3
4
map 4
done
[ 2, 4, 6, 8 ]
*/
Float32Array.from(g(), mapper);
/*
1
2
3
4
done
map 1
map 2
map 3
map 4
Float32Array [ 2, 4, 6, 8 ]
*/
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.