Skip to content

Instantly share code, notes, and snippets.

@ljharb

ljharb/test.js Secret

Created July 17, 2019 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljharb/896ad592accdbd783d5ec1d44e978b76 to your computer and use it in GitHub Desktop.
Save ljharb/896ad592accdbd783d5ec1d44e978b76 to your computer and use it in GitHub Desktop.
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