Published unlisted
Edited
May 24, 2019
1 star
Insert cell
Insert cell
div_iterable = () => map(
v => html`<div>${v}</div>`,
range(4))
Insert cell
Array.from(range(10))
Insert cell
Array.from(div_iterable())
Insert cell
html`
${[...div_iterable()]}
`
Insert cell
html`
${div_iterable()}
`
Insert cell
new Set(div_iterable())
Insert cell
html`
${new Set(div_iterable())}
`
Insert cell
Insert cell
({ *[Symbol.iterator]() {
const a = 5;
yield a;
}})
Insert cell
Insert cell
({ [Symbol.iterator]: function*() {
const a = 5;
yield a;
}})
Insert cell
Insert cell
Insert cell
wrap = function wrap (iterable) {
return { *[Symbol.iterator]() { yield* iterable; } }; }
Insert cell
Insert cell
range = function range(start, stop, step=1) {
if (stop == null) stop = start, start = 0;
return { *[Symbol.iterator]() {
for (let i = start; i < stop; i += step) yield i; }}; }
Insert cell
Insert cell
map = function* map(callback, ...iterables) {
const iterators = Array.from(iterables, (iter) => iter[Symbol.iterator]());
const n = iterators.length;
while (true) {
const args = Array(iterators.length);
let anydone = 0;
for (let i = 0; i < n; i++) {
const {done, value} = iterators[i].next();
args[i] = value;
anydone |= done; }
if (anydone) break;
yield callback(...args); }}
Insert cell
Insert cell
map1 = function* map1(callback, iterable) {
for (let arg of iterable) yield callback(arg); }
Insert cell
Insert cell
spreadmap = function* spreadmap(callback, iterable) {
for (let args in iterable)
yield callback(...args); }
Insert cell
Insert cell
filter = {
const identity = function identity(x) { return x; };
return function* filter(callback, iterable) {
if (callback == null) callback = identity;
for (let item of iterable) if (callback(item)) yield item; }; }
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more