Published
Edited
Jul 3, 2022
1 star
Also listed in…
Tips and Utilities
Insert cell
# Hello, lazy.js!
Insert cell
Lazy = import('https://cdn.skypack.dev/lazy.js@0.5.1?min')
Insert cell
Insert cell
Insert cell
people = {
const pArr = []
for(let i =0; i< 20000; i++){
pArr[i] = {
firstName: `foo${Math.floor(Math.random() * 1000)}`,
lastName: `guh${Math.floor(Math.random() * 1000)}`
}
}
yield pArr;
}
Insert cell
{
yield Lazy.default(people)
.pluck('lastName')
.filter(function(name) { return name.startsWith('guh'); })
.take(5)
.value();
}
Insert cell
{
yield Lazy.generate(Math.random)
.map(function(e) { return Math.floor(e * 1000) + 1; })
.uniq()
.take(300)
.value()
}
Insert cell
cout = html`<div> waiting ... </div>`
Insert cell
{
// re run this to see the async waiting happen
Lazy.generate(Lazy.identity)
.async(1000) // specifies a 1-second interval between each element
.map(function(x) { return String.fromCharCode(x + 65); })
.take(26)
.each(function(char) {
console.log(char)
console.log(cout.appendChild(html`<div>${char}</div>`))
});
}
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