Published
Edited
Apr 28, 2021
2 stars
Insert cell
Insert cell
Insert cell
{
// magically retrieve the data from a file or whatever
const entries = data();

return format(entries[input_v1]);
}
Insert cell
function format(results) {
return results.join('\n');
}
Insert cell
Insert cell
Insert cell
{
const is_even = num => num % 2 === 0;

const even_arr = [1,3,4,5].filter(is_even).map(val => val.toString());
const empty_arr = [].filter(is_even).map(val => val.toString());

return {even: even_arr.join(', '), empty: empty_arr.join(', ')};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const search = (data, input) => Maybe(data[input]);

const search_word = word => search(entries, word)
.map(format)
.unwrap_or('word not found');
return Maybe(input_v2).map(search_word).unwrap_or('');
}
Insert cell
Insert cell
Insert cell
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
Insert cell
Insert cell
Insert cell
{
const search = create_search(entries, true);
const search_name = create_search(entries, false);
const search_word = word => search(word)
.or_else(() => search_name(word))
.map(format)
.unwrap_or('word not found');
return Maybe(input_v3).map(search_word).unwrap_or('');
}
Insert cell
Insert cell
Insert cell
fzf = {
return new FuzzySearch(
Object.keys(entries),
[],
{caseSensitive: false, sort: true}
);
}
Insert cell
Insert cell
function suggest(word) {
const matches = fzf.search(word);
return Maybe(matches[0]);
}
Insert cell
Insert cell
function confirm_word_v1(container) {
return async function(value) {
const confirmed = value && await make_prompt({
msg: `Did you mean "${value}"?`,
container
});

if(confirmed) {
return value;
}
}
}
Insert cell
Insert cell
Insert cell
Insert cell
suggest_word_v1 = {
return value => () => suggest(value)
.and_then(Task.of)
.map(confirm_word_v1(viewof input_v4.lastElementChild))
.map(v => search(v).unwrap_or(''));
}
Insert cell
Insert cell
Insert cell
{
const search_word = word => search(word)
.or_else(() => search_name(word))
.or_else(suggest_word_v1(word))
.map(format)
.unwrap_or('word not found');
return Maybe(input_v4).map(search_word).unwrap_or('');
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function update_input(value) {
viewof input_v5[0].value = value;
}
Insert cell
Insert cell
Insert cell
Insert cell
{
const search_word = word => search(word)
.or_else(() => search_name(word))
.or_else(suggest_word_v2(word))
.map(format)
.unwrap_or('word not found');
return Maybe(input_v5).map(search_word).unwrap_or('');
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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