Notebooks 2.0 is here.

Published
Edited
Apr 24, 2020
1 fork
Importers
Insert cell
Insert cell
Insert cell
a = new NonEmptyMap([[1, 'uno'], [2, 'dos']])
Insert cell
Insert cell
a instanceof Map
Insert cell
[...a.keys()]
Insert cell
a.size
Insert cell
Insert cell
new NonEmptyMap(a)
Insert cell
Insert cell
// Error
a.clear()
Insert cell
Insert cell
{
const d = new NonEmptyMap(a);
Map.prototype.clear.call(d);
return d;
}
Insert cell
Insert cell
b = {
const b = new NonEmptyMap([[1, 'uno']]);
// Error
b.delete(1);
return b;
}
Insert cell
Insert cell
// Error
c = new NonEmptyMap([])
Insert cell
Insert cell
class NonEmptyMap extends Map {
constructor(iterable) {
super(iterable);
if (this.size === 0) {
throw new Error('NonEmptyMap cannot be empty');
}
}
delete(key) {
if (this.size === 1) {
throw new Error(`Cannot delete the only NonEmptyMap element: ${key}`);
}
super.delete(key);
}
clear() {
throw new Error('NonEmptyMap cannot be cleared');
}
}
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