Published
Edited
Jan 16, 2021
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
plus1 = x => x === null ? x : x + 1
Insert cell
Insert cell
plus1([3])
Insert cell
Insert cell
map(plus1, [3])
Insert cell
Insert cell
thing = value => ({
value,
map: morphism => morphism(value)
// -------- -----
// | |
// | value to be morphed
// |
// Morphism passed into map
})
Insert cell
thing(5).map(double)
Insert cell
Insert cell
double = curry(x => 2 * x)
Insert cell
maybe = value => ({
value,
map: morph => morph(value)
})
Insert cell
maybe(3)
Insert cell
map(plus1, maybe(3))
Insert cell
either = (left, right) => ({
left,
right,
map: morph => right
? { left, right: morph(right) }
: { left: morph(left), right }
})
Insert cell
either(1)
Insert cell
either(1,2)
Insert cell
map(plus1, either(1))
Insert cell
map(plus1, either(1, 2))
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