Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(website): update getting started docs #52

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions website/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,19 @@ import {
} from 'lfi'

// The file has one sloth name per line
const filename = `every-sloth-name.txt`
const FILENAME = `every-sloth-name.txt`
const API_URL = `https://random-word-form.herokuapp.com/random/adjective`

const slothSquadStatementsPromise = pipe(
// Create an async iterable over the file lines, in this case sloth names
(await fetch(new URL(`https://lfi.dev/${filename}`))).body,
(await fetch(new URL(`https://lfi.dev/${FILENAME}`))).body,
flatMapAsync(chunk => new TextDecoder().decode(chunk).split(`\n`)),
// Chunk the sloth names into array groups of 4, also known as a sloth squad
chunkAsync(4),
// Transform each sloth squad into a statement by asynchronously querying an
// API for an adjective to describe the squad
mapAsync(async slothSquad => {
const [adjective] = await (
await fetch(`https://random-word-form.herokuapp.com/random/adjective`)
).json()
const [adjective] = await (await fetch(API_URL)).json()
const leadingSloths = slothSquad.slice(0, 3)
const trailingSloth = slothSquad.at(-1)
return `${leadingSloths.join(`, `)}, and ${trailingSloth} are ${adjective}!`
Expand Down Expand Up @@ -195,11 +194,12 @@ import {
} from 'lfi'

// The file has one sloth name per line
const filename = `every-sloth-name.txt`
const FILENAME = `every-sloth-name.txt`
const API_URL = `https://random-word-form.herokuapp.com/random/adjective`

const slothSquadStatementsPromise = pipe(
// Create an async iterable over the file lines, in this case sloth names
(await fetch(new URL(`https://lfi.dev/${filename}`))).body,
(await fetch(new URL(`https://lfi.dev/${FILENAME}`))).body,
flatMapAsync(chunk => new TextDecoder().decode(chunk).split(`\n`)),
// Chunk the sloth names into array groups of 4, also known as a sloth squad
chunkAsync(4),
Expand All @@ -211,9 +211,7 @@ const slothSquadStatementsPromise = pipe(
// API for an adjective to describe the squad, all concurrently with other
// squads
mapConcur(async slothSquad => {
const [adjective] = await (
await fetch(`https://random-word-form.herokuapp.com/random/adjective`)
).json()
const [adjective] = await (await fetch(API_URL)).json()
const leadingSloths = slothSquad.slice(0, 3)
const trailingSloth = slothSquad.at(-1)
return `${leadingSloths.join(`, `)}, and ${trailingSloth} are ${adjective}`
Expand All @@ -225,6 +223,7 @@ const slothSquadStatementsPromise = pipe(
)

console.log(await slothSquadStatementsPromise)
// NOTE: This order may change between runs
//=> [
//=> 'strawberry, max, bitsy, and tommy jolly!',
//=> 'ava, brooke, lottie, and jeremiah are beloved!',
Expand Down