Platform
Resources
Pricing
Sign in
Contact us
Observable
The end-to-end solution for building and hosting better data apps, dashboards, and reports.
Workspace
Fork
Published
Generators
By
Mike Bostock
Edited
May 9, 2018
2 forks
20 stars
Generators
Introduction to generators
Generator Cells, Functions and Objects
Variable Speed Generator
Custom Generators
Pause a Generator
Invalidation
Insert cell
Insert cell
{
for
(
let
i
=
0
;
i
<
60
;
++
i
)
{
yield
i
;
}
}
Insert cell
Insert cell
range
(
60
)
Insert cell
function
*
range
(
n
)
{
for
(
let
i
=
0
;
i
<
n
;
++
i
)
{
yield
i
;
}
}
Insert cell
Insert cell
new
Range
(
60
)
Insert cell
class
Range
{
constructor
(
n
)
{
this
.
n
=
n
;
this
.
i
=
0
;
}
next
(
)
{
return
this
.
i
>=
this
.
n
?
{
done
:
true
}
:
{
done
:
false
,
value
:
this
.
i
++
}
;
}
return
(
)
{
this
.
i
=
this
.
n
;
return
{
done
:
true
}
;
}
}
Insert cell
Insert cell
{
const
n
=
60
;
let
i
=
0
;
return
{
next
:
(
)
=>
{
return
i
>
n
?
{
done
:
true
}
:
{
done
:
false
,
value
:
i
++
}
;
}
,
return
:
(
)
=>
{
i
=
n
;
return
{
done
:
true
}
;
}
}
;
}
Insert cell
Insert cell
yield
*
[
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
]
Insert cell
yield
*
iterableRange
(
60
)
Insert cell
function
iterableRange
(
n
)
{
return
{
[
Symbol
.
iterator
]
:
(
)
=>
{
let
i
=
0
;
return
{
next
:
(
)
=>
{
return
i
>
n
?
{
done
:
true
}
:
{
done
:
false
,
value
:
i
++
}
;
}
}
;
}
}
;
}
Insert cell
Insert cell
{
for
(
const
i
of
iterableRange
(
60
)
)
{
yield
i
;
}
}
Insert cell
Insert cell
yield
*
await
asyncIterableRange
(
60
,
1000
)
Insert cell
function
asyncIterableRange
(
n
,
delay
)
{
return
{
[
Symbol
.
asyncIterator
]
:
(
)
=>
{
let
i
=
0
return
{
next
:
async
(
)
=>
{
await
Promises
.
delay
(
delay
)
;
return
i
>
n
?
{
done
:
true
}
:
{
done
:
false
,
value
:
i
++
}
;
}
}
;
}
}
;
}
Insert cell
Insert cell
{
for
await
(
const
i
of
asyncIterableRange
(
60
,
1000
)
)
{
yield
i
;
}
}
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
range
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Range
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
iterableRange
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
asyncIterableRange
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML