Platform
Resources
Pricing
Sign in
Get started
深度碎片
as simple as possible
Workspace
Fork
Published
Observable tutorials
By
深度碎片
Edited
Oct 21, 2019
Fork of
Custom Generators
Insert cell
Insert cell
generator_cell
=
{
for
(
let
i
=
0
;
i
<
60
;
++
i
)
{
yield
i
;
}
}
Insert cell
Insert cell
a
=
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
(
new
Range
(
60
)
)
.
i
Insert cell
(
new
Range
(
60
)
)
.
next
(
)
Insert cell
(
new
Range
(
60
)
)
.
return
(
)
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
forof
=
{
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
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
generator_cell
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
generator_function_object
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
a
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
range
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
generator_class
Edit
Add comment
Copy import
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
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
generator_object
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
delegating_iterable
Edit
Add comment
Copy import
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
forof
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
async_yield_iterable
Edit
Add comment
Copy import
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