Public
Edited
Feb 12, 2023
Insert cell
Insert cell
class Identity extends Inspectable {
constructor(x) {
super();
this.$value = x;
}

static of(x) {
return new Identity(x);
}

map(fn) {
return Identity.of(fn(this.$value));
}
}
Insert cell
// map :: Functor f => (a -> b) -> f a -> f b
map = R.curry((fn, functor) => functor.map(fn))
Insert cell
// append :: String -> String
append = R.curry((a,b) => b + a)
Insert cell
Identity.of("flamethrowers")
.map(append(" away"))
.map(R.prop("length"))
.inspect()
Insert cell
R.compose(map(append(" away")), Identity.of)("flamethrowers").inspect()
Insert cell
class Maybe extends Inspectable {
$value;

constructor(x) {
super();
this.$value = x;
}

static of(x) {
return new Maybe(x);
}

isNothing() {
return this.$value === null || this.$value === undefined;
}

map(fn) {
return this.isNothing() ? this : Maybe.of(fn(this.$value));
}

valueToString() {
return this.isNothing() ? 'Nothing' : `Just ${this.$value}`
}
}
Insert cell
Maybe.of("0123")
.map(R.prop(3))
.map((x) => "abc"[x])
.map((x) => x + x)
.inspect()
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more