Published
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.
Learn more