Published
Edited
Oct 2, 2019
1 fork
Insert cell
Insert cell
ten$ = obs.range(1,10)
Insert cell
ten$.view()
Insert cell
Insert cell
ten$
.bufferCount(3)
.view({size:40})
Insert cell
tenSec$ = obs.interval(1000).take(10)
Insert cell
tenSec$.view({size:40})
Insert cell
tenSec$.buffer(obs.interval(2000)).view({size:40})
Insert cell
tenSec$.windowCount(3).flatMap(x => x.sum()).view()
Insert cell
Insert cell
tenSec$.window(obs.interval(3000)).flatMap(x => x.min()).view()
Insert cell
obs.of("hello", "world", "foo").scan( (acc, word) => acc += word.length, 0 ).view()
Insert cell
obs.interval(1000).take(10).map(util.random)
.scan( (acc, x) => ({ prev: x, color: acc.prev > x ? "white" : "black"}), {prev:0})
.pluck('color')
.view()
Insert cell
Insert cell
avg = arr => arr.length ? arr.reduce( (a,b) => a+b, 0)/arr.length : 0
Insert cell
windowShift = (arr, x, length) => [...arr, x].slice(-length)
Insert cell
ten$
.scan( (acc, x) => ({arr: windowShift(acc.arr, x, 4), avg: avg(acc.arr) }), {arr:[]})
.pluck('avg')
.view({size: 30})
Insert cell
Insert cell
validate = x => { if(x == 5) throw "ouch" }
Insert cell
validated$ = ten$.do(validate)
Insert cell
validated$.view()
Insert cell
validated$.catch(x => obs.of(10)).view()
Insert cell
validated$.retry(2).view()
Insert cell
ten$.flatMap( x => obs.of(x).do(validate).catch(x => obs.empty()) ).view()
Insert cell
ten$.flatMap( x => obs.of(x).do(console.log).do(validate).retry(2) ).view()
Insert cell
obs.never().view()
Insert cell
obs.empty().view()
Insert cell
obs.of(1).view()
Insert cell
obs.throw("ouch").view()
Insert cell
obs.concat( obs.of(1)).materialize().values()
Insert cell
obs.concat( obs.of(1), obs.throw("ouch")).materialize().values()
Insert cell
info[2]
Insert cell
Insert cell
wave$ = (length) => obs.range(1,36).map( x => Math.round( 128 * (1 + Math.sin(x/length)) ) )
Insert cell
wave$(10).map(x => `rgb(${x},${x},${x})`).view()
Insert cell
red$ = wave$(2)
Insert cell
green$ = wave$(3)
Insert cell
blue$ = wave$(5)
Insert cell
Insert cell
obs.zip(red$, green$, blue$, (x,y,z) => `rgb(${x},${y},${z})`).view()
Insert cell
colors = obs.zip(red$, green$, blue$, (x,y,z) => `rgb(${x},${y},${z})`).repeat()
Insert cell
clix$ = obs.fromEvent(document, 'click').pluck('x').timeout(30000)
Insert cell
clix$.view({size:40})
Insert cell
clix$.combineLatest(obs.interval(1000), (x,y) => x*y ).view({size:40})
Insert cell
Insert cell
clix$.withLatestFrom(obs.interval(1000), (x,y) => x*y ).view({size:40})
Insert cell
Insert cell
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