Platform
Resources
Pricing
Sign in
Get started
Jesse Varnado
Workspace
Fork
Published
By
Jesse Varnado
Edited
May 8, 2020
1 star
Insert cell
md
`# Factorial with Streams!`
Insert cell
factorial
(
100
)
Insert cell
factorial
=
(
n
)
=>
integersStream
(
)
.
scan1
(
(
a
,
b
)
=>
BigInt
(
a
)
*
BigInt
(
b
)
)
.
take
(
n
)
.
last
(
)
.
toPromise
(
Promise
)
Insert cell
{
const
stream
=
integersStream
(
)
.
flatMap
(
delay
(
1000
)
)
return
observeHighland
(
stream
.
zip
(
stream
.
observe
(
)
.
scan1
(
(
a
,
b
)
=>
BigInt
(
a
)
*
BigInt
(
b
)
)
)
.
map
(
(
[
n
,
factorial
]
)
=>
(
{
n
,
factorial
}
)
)
)
}
Insert cell
observeHighland
(
integersStream
(
)
.
flatMap
(
delay
(
1000
)
)
)
Insert cell
integersStream
=
(
)
=>
highland
(
integersGenerator
(
)
)
Insert cell
integersGenerator
=
function
*
(
)
{
let
i
=
1
while
(
true
)
yield
i
++
}
Insert cell
import
{
observeHighland
,
delay
}
from
'@jessevarnado/highland-js-examples'
Insert cell
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
factorial
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
integersStream
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
integersGenerator
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
highland
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML