Published
Edited
Dec 28, 2020
Insert cell
md`# Point-Free Style`
Insert cell
Insert cell
{
const users = [
{ name: 'Peter', email: 'peter@example.com' },
{ name: 'Bob', email: 'bob@example.com' },
]

const getName = user => user.name

return users.map(user => getName(user))
}
Insert cell
md`When we map through the array of users we call the user variable a point because we name and reference this variable explicitly when calling \`getName()\`. In order to go point-free we simply leave out the mention of the variable and pass the function \`getName()\` directly to the \`.map()\`.`
Insert cell
{
const users = [
{ name: 'Peter', email: 'peter@example.com' },
{ name: 'Bob', email: 'bob@example.com' },
]

const getName = user => user.name
return users.map(getName)
}
Insert cell
Insert cell
{
return ['1', '2', '3'].map(num => parseInt(num))
}
Insert cell
{
return ['1', '2', '3'].map(parseInt)
}
Insert cell
Insert cell
{
const unary = f => (...args) => f(args[0])

return ['1', '2', '3'].map(unary(parseInt)) // [1, 2, 3]
}
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